|
Hi There,
I've spent a number of years away from C and C++ but recently decided to get back to it. I downloaded the latest VS2013 C++ and off I went.
My challenge is that I cannot get the DLL I need to use to link in. I've generated a .def file using Dumpbin and then used that to create a .LIB for the DLL. I've put the lib in the Additional Dependencies of the Linker properties and added the directory to VC++ directories. It is definitely reading the lib because if I name it wrong then I get a can't find the lib error.
I am still getting a LNK2019 unresolved externals message. I tried dumping the lib using dumpbin /EXPORTS and it has all the functions (though they are preceeded by _) I did even try using the _Functionname.. names in the code but still no luck.
It feels like in the 10-15 years in between C++ should have got a lot easier. I sort of expected to just drop the dll in the project and off it would go. Hey ho, anyone that can point me at what I'm doing wrong I would be grateful
Trevor
|
|
|
|
|
I assume you're using a header file to describe the functions that live in the DLL?
If so, try putting this around the function declarations:
extern "C"
{
}
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Hi Richard,
Thank you very much, I knew it would be something simple I just could not see it!
All linking okay now
Trevor
|
|
|
|
|
I'm new to C++ programming and also new to posting on forums. I'm sorry if I don't enter this correctly for my first post. I am trying to create a program that will display a predetermined shipping charge for 2 zip codes. Program should send error messages if the zip code entered is not 5 digits long, not all 5 numbers, or does not begin with 605 or 606. Below is the code I have written so far. Sentinel value of -1 should end the program. The messages seem to be correct when I enter test data but it keeps looping the same message repeatedly and I have to close the program to stop it. Can anyone tell me what I've done wrong?
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
//function prototype
char verifyNumbers(string);
int main ()
{
//declare variables
string zip = " ";
char isAllNumbers = ' ';
const string invalid_length = "Invalid length";
const string not_all_numbers = "Not all numbers";
const string invalid_shipping = "Zip code is not valid for shipping charges";
//get input (zip code)
cout << "Enter 5 digit zip code (-1 to end): ";
getline(cin, zip);
//verify input
while (zip != "-1")
{
if (zip.length() == 5)
{
isAllNumbers = verifyNumbers(zip);
if (isAllNumbers == 'Y')
{
if (zip.find ("605", 0) == 0 || zip.find ("606", 0) == 0)
{
if (zip.find("605", 0) == 0)
{
cout << "Shipping is $25" << endl;
}
else
cout << "Shipping is $30" << endl;
//end if
}
else
cout << invalid_shipping << endl;
//end if
}
else
cout << not_all_numbers << endl << endl;
//end if
}
else
cout << invalid_length << endl << endl;
//end if
cout << "Enter 5 digit zip code (-1 to end): ";
getline(cin, zip);
} //end while
//calculate shipping charges
//display output
} //end of main function
//*****function definitions*****
char verifyNumbers(string zip) //determine if each character is a number
{
//declare variables
string currentChar = "";
int x = 0;
char isNumber = 'Y';
//determine if characters are all numbers
while (x < 5 && isNumber == 'Y')
{
currentChar = zip.substr(x, 1);
if (currentChar >= "0" && currentChar <= "9")
x += 1;
else
isNumber = 'N';
//end if
}//end while
return isNumber;
} //end of verifyNubmers function
I really appreciate any help I can get!
Thank you! Carla
-- modified 11-Apr-14 22:40pm.
|
|
|
|
|
The thing that's causing the infinite looping is that once you enter the "verify input" loop, there is no way out of it so that the user can enter another number.
Put the prompt and the call to getline inside the while (zip != "-1") loop so that if the user enters an incorrect value, they can enter another value on the next iteration of the loop.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
That worked perfectly. Thank you so much!
Thanks,
Carla
|
|
|
|
|
Is it posible to draw on two monitors, perfect synchronously ? I had taked from here[^] an good example of how can I handle two monitors, but if I want to draw something on them, the drawing is no synchronously ... could you guide me in order to do that ?
Thank you.
|
|
|
|
|
Even with two threads running it is impossible to guarantee exact synchronous actions.
|
|
|
|
|
And how would you synchronize the hardware refresh period? I would drop this idea.
|
|
|
|
|
I didn't put this problem, my goal is to draw the same image, on two monitors, in the same time, at leat to begin to draw the same image in the same time. Any idea will be welcomed.
|
|
|
|
|
Hi,
I am developing a MFC application on Windows 8.1 using VS-2005.
Requirement is to customize Folder Explorer for a specific purpose. I want to create own pidl for folder and its contents.
When I will open a particular folder, application's should inherit Win-8 Windows explorer.
I want to set customized icon for folder on top left corner(On Win-8) and at the root of address bar.
I am using GetBindToObject, GetUIObjectOf, CreateViewObject, GetIconLocation and Extract method in ShellFolderImpl class. Please give me some sample source code or idea to do that. I have already studied URL - [http://msdn.microsoft.com/en-us/library/windows/desktop/cc144093%28v=vs.85%29.aspx ] but it is not working.
This method is in ShellFolderImpl class
BindToObject, CreateViewObject, etc functions are working correctly.......
Icon index and Icon is loaded correctly. bcz I saved created icon from Extract method.
But emplty icon is placed at specified place on folder as given in above image.
1. IExtractIcon interface is called from GetUIObjectOf method correctly.
2. GetIconLocation method gives correct output Index for Icon.
3. Extract function gives correct output for hIcon.
But problem is that Icon assigned to displayed was not correctly displayed at AddressBar and Caption Bar(Top-left corner).
Currently, Icon is displayed on AddressBar and Caption Bar(Top-left corner) was empty file icon.
when I set :
HRESULT ExtIcon::ExtractImpl(UINT nIconIndex, HICON* phiconLarge, HICON* phiconSmall)
{
phiconLarge = NULL;
phiconSmall= NULL;
}
I got folder icon on the AddressBar and Caption Bar.
--------------------------------------------------------------------------------------
STDMETHODIMP ShellFolderImpl::GetUIObjectOf ( HWND , UINT uCount,
LPCITEMIDLIST* pPidl, REFIID riid,
LPUINT, void** ppvReturn )
{
try
{
*ppvReturn = NULL;
if( uCount != 1 )
return E_FAIL;
if( IsEqualIID(riid, IID_IExtractIconA)|| IsEqualIID(riid, IID_IExtractIconW))
{
CComObject<ExtIcon>* pExtractIcon;
HRESULT hr = CComObject<ExtIcon>::CreateInstance ( &pExtractIcon );
if (FAILED(hr))
return hr;
pExtractIcon->Init(GetUnknown());
pExtractIcon->AddRef();
pExtractIcon->SetMyPIDL((LPITEMIDLIST)*pPidl);
hr = pExtractIcon->QueryInterface(riid, ppvReturn);
pExtractIcon->Release();
return hr;
}
catch(...){}
return E_NOINTERFACE;
}
Extract Icon handler is as :
#pragma once
#include "resource.h"
#include "PluginRes.h"// main symbols
#include "pidlmgr.h"
#include "ExplorerPlugIn.h"
class ATL_NO_VTABLE ExtIcon :
public CComObjectRootEx<CComSingleThreadModel>,
public CComCoClass<ExtIcon, &CLSID_ExtIcon>,
public IDispatchImpl<IExtIcon, &IID_IExtIcon, &LIBID_ExplorerPlugInLib, 1, 0>,
public IExtractIconA,
public IExtractIconW
{
public:
ExtIcon()
{
}
ExtIcon(LPCITEMIDLIST pidl);
DECLARE_REGISTRY_RESOURCEID(IDR_EXTICON)
BEGIN_COM_MAP(ExtIcon)
COM_INTERFACE_ENTRY_IID(IID_IExtractIconA, IExtractIconA)
COM_INTERFACE_ENTRY_IID(IID_IExtractIconW, IExtractIconW)
COM_INTERFACE_ENTRY(IExtIcon)
COM_INTERFACE_ENTRY(IDispatch)
END_COM_MAP()
DECLARE_PROTECT_FINAL_CONSTRUCT()
HRESULT FinalConstruct()
{
return S_OK;
}
void FinalRelease()
{
}
public:
STDMETHOD(GetIconLocation)(THIS_ UINT, LPSTR, UINT, int* piIndex, UINT* pwFlags)
{
return GetIconLocationImpl(piIndex, pwFlags);
}
STDMETHOD(Extract)(THIS_ LPCSTR, UINT nIconIndex, HICON* phiconLarge, HICON* phiconSmall, UINT)
{
return ExtractImpl(nIconIndex, phiconLarge, phiconSmall);
}
STDMETHOD(GetIconLocation)(THIS_ UINT, LPWSTR, UINT, int* piIndex, UINT* pwFlags)
{
return GetIconLocationImpl(piIndex, pwFlags);
}
STDMETHOD(Extract)(THIS_ LPCWSTR, UINT nIconIndex, HICON* phiconLarge, HICON* phiconSmall, UINT)
{
return ExtractImpl(nIconIndex, phiconLarge, phiconSmall);
}
void Init(IUnknown *pUnkOwner);
void SetMyPIDL(LPITEMIDLIST pidl)
{
m_pidl = pidl;
}
enum BoxType
{
PUBLIC,
PRIVATE
};
private:
HRESULT GetIconLocationImpl(int*, UINT*);
HRESULT ExtractImpl(UINT, HICON*, HICON*);
CPidlMgr* m_pPidlMgr;
LPITEMIDLIST m_pidl;
BOOL m_bIsOpenIcon;
protected:
CComPtr<IUnknown> m_UnkOwnerPtr;
DWORD m_ObjRefCount;
};
OBJECT_ENTRY_AUTO(__uuidof(ExtIcon), ExtIcon)
modified 11-Apr-14 8:01am.
|
|
|
|
|
Dear all:
I implement a application, when I get a touch data from WM_INPUT and touch count more than previous, it will play sound, My code show as below:
void CTouchSoundTrayDlg::OnRawInput(UINT nInputCode, HRAWINPUT hRawInput)
{
UINT data_size = 0;
BOOL bGot = FALSE;
GetRawInputData(hRawInput, RID_INPUT, NULL, &data_size, sizeof(RAWINPUTHEADER));
vector<BYTE> data;
data.resize (data_size);
if(GetRawInputData (hRawInput, RID_INPUT, &data [0], &data_size, sizeof(RAWINPUTHEADER))!=data_size)
{
}
RAWINPUT* raw = (RAWINPUT*)(&data [0]);
if (raw->header.dwType == RIM_TYPEHID)
{
RID_DEVICE_INFO device_info;
UINT info_size = sizeof(RIDI_DEVICEINFO);
GetRawInputDeviceInfo ( raw->header.hDevice, RIDI_DEVICEINFO, (LPVOID)&device_info,&info_size);
if(device_info.hid.dwVendorId = VENDER_ID)
{
g_CurFrameTime = GetTickCount64();
if(g_CurFrameTime - g_PreFrameTime > 30)
{
g_PreUsedSize = 0;
g_CurUsedSize = 0;
}
g_PreFrameTime = g_CurFrameTime;
DigitizerData* result = (DigitizerData*)(raw->data.hid.bRawData);
g_CurUsedSize = result->active_touch_count;
if(g_CurUsedSize <= 5)
{
if(g_PreUsedSize < g_CurUsedSize)
{
PlaySound(m_WavPath, NULL, SND_FILENAME|SND_ASYNC );
}
bGot = TRUE;
}
if(bGot)
{
g_PreUsedSize = g_CurUsedSize;
}
}
}
Default();
}
My question is
when I touch, it will play sound, and the using memory in task manager will be add, When play music is finish, the using memory is still, will not free
,why?
I try to disable the playSound api in my code, and the using memory is stable.
Thank your help, Victor
|
|
|
|
|
I would assume that data structures are initialized to play the sound, and then the data structures are kept for the next sound to play.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Hi,
I am trying to rewrite an old VC++ wrapper class around MS Word Automation - it used to use *.tli and *.tlh files, but now MS recommends just using the *.h files which get generated. So, that is another level of complexity.
So, I got so far, now I am wondering what to do next.
Here are some code snips, the real code obviously has error correction etc., so here is what I have so far;
IDispatch *pWordInst;
CApplication *pWordApp;
CDocument0 *pDoc;
IUnknown *pUnknown;
HRESULT res = CoInitialize(NULL);
CLSID clsid;
HRESULT hr = CLSIDFromProgID(L"Word.Application", &clsid);
hr = CoCreateInstance(clsid, NULL, CLSCTX_LOCAL_SERVER, IID_IDispatch, (void **)&pWordInst);
pUnknown = NULL;
REFIID iid2 = __uuidof(IUnknown);
hr = pWordInst->QueryInterface(iid2, (void **)&pUnknown);
So, now I need to get the Application and Document objects (assuming that this code creates a new document as it used to).
I am guessing I need a getApplication() but what MS class do I use for that?
Once I have the Application, then I can get the Document, presumably with a get_Documents() or get_ActiveDocument()?.
After that I guess it will run like my older version used to.
Any help and advice would be great.
Many Thanks,
Bryan.
|
|
|
|
|
|
I've always done it like:
_Application app;
Documents docs;
_Document doc;
if (app.CreateDispatch("Word.Application") == TRUE)
{
docs = app.GetDocuments();
doc = docs.Open(COleVariant(strFileName), ...);
docs.Close(vtFalse, vtOptional, vtOptional);
app.Quit(vtOptional, vtOptional, vtOptional);
} Not sure if that helps you or not.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
We were given a task to use lists and iterators. We were supposed to make them from scratch. I'm done with that. The problems that I'm having are as following:
1. I'm not able to access the list made of Course datatype which is present in each Student instance. Does this mean I need to make an iterator for that course list inside the student class?
2. Similarly since I don't have direct access to The course list so I added the course into the Student list through the student objects not through the iterator. How can I do it through the iterator?
3. Printing of a particular student and his courses is not happening as my iterator made for student only prints out the students, not the courses present in their courselist. How to do that?
Here's the code:
<pre lang="c++">
#include <iostream>
#include <string>
using namespace std;
const int ILLEGAL_SIZE = 1;
const int OUT_OF_MEMORY = 2;
const int NO_SPACE = 3;
const int ILLEGAL_INDEX = 4;
const int ILLEGAL_REFERNCE = 5;
const int COURSE_LIMIT_REACHED = 6;
template <class T>
class ListIterator;
template <class T>
class OrderedList {
friend class ListIterator<T>;
private:
int maxSize;
int currentSize;
T *listArray;
bool removeAt(int index) {
if(index < 0 || index >= currentSize) throw ILLEGAL_INDEX;
else {
for(int i=index;i<currentSize;i++)
listArray[i] = listArray[i+1];
currentSize--;
return true;
}
}
public:
OrderedList(int size);
OrderedList(const OrderedList& copy);
~OrderedList();
void setData(T s);
T getData(int i);
int getCurrent() { return currentSize; }
bool isFull();
bool isEmpty();
int isPresent(T value);
void insert(T value);
bool remove(T value);
int search(T value);
void printData();
const OrderedList& operator = (const OrderedList& assignment);
};
template <class T>
OrderedList<T>::OrderedList(int size) {
if(size < 0) throw ILLEGAL_SIZE;
maxSize = size;
listArray = new T[maxSize];
if(listArray == NULL) throw OUT_OF_MEMORY;
currentSize = 0;
}
template <class T>
OrderedList<T>::OrderedList(const OrderedList& copy) {
maxSize = copy.maxSize;
currentSize = copy.currentSize;
listArray = new T[maxSize];
for(int i=0;i<currentSize;i++) {
listArray[i] = copy.listArray[i];
}
}
template <class T>
const OrderedList<T>& OrderedList<T>::operator= (const OrderedList& assignment) {
if(this != &assignment) {
currentSize = assignment.currentSize;
delete [] listArray;
listArray = new T[maxSize];
for(int i=0;i<currentSize;i++) {
listArray[i] = assignment.listArray[i];
}
}
return *this;
}
template <class T>
OrderedList<T>::~OrderedList() {
delete [] listArray;
}
template <class T>
void OrderedList<T>::setData(T s) {
listArray[currentSize] = s ;
currentSize++;
}
template <class T>
T OrderedList<T>::getData(int i) {
return listArray[i];
}
template <class T>
bool OrderedList<T>::isEmpty() {
return (currentSize == 0);
}
template <class T>
bool OrderedList<T>::isFull() {
return (currentSize == maxSize);
}
template <class T>
int OrderedList<T>::isPresent(T value) {
return(search(value));
}
template <class T>
int OrderedList<T>::search(T value) {
int low = 0;
int mid;
int high = currentSize-1;
while(low<=high) {
mid = (low + high)/2;
if(value == listArray[mid])
return mid;
else if(value > listArray[mid])
low = mid + 1;
else
high = mid - 1;
}
return -1;
}
template <class T>
void OrderedList<T>::insert(T value) {
if(isFull()) throw NO_SPACE;
else {
int i = currentSize;
while( i > 0 && value < listArray[i-1]) {
listArray[i] = listArray[i-1];
i--;
}
listArray[i] = value;
currentSize++;
}
}
template <class T>
bool OrderedList<T>::remove(T value) {
int index = search(value);
if(index == -1) return false;
else {
return removeAt(index);
}
}
template <class T>
void OrderedList<T>::printData() {
for(int i=0;i<currentSize;i++) {
cout << listArray[i] << endl;
}
}
class Course {
private:
string ID;
double GPA;
public:
Course(): ID(""),GPA(0) {}
Course(string id,double gpa): ID(id),GPA(gpa) {}
double getGPA() { return GPA; }
void printCourse() { cout << "Course ID: " << ID << " " << "GPA: " << GPA << endl; }
friend ostream& operator<< (ostream & out, const Course& course) { out << course.ID << " " << course.GPA << endl; return out; }
bool operator< (Course c) { if (ID < c.ID) return true; else return false; }
bool operator> (Course c) { if (ID > c.ID) return true; else return false; }
bool operator== (Course c) { if (ID == c.ID) return true; else return false; }
};
class Student {
private:
string name;
int rNo;
int noOfCourses;
double CGPA;
OrderedList<Course> courseList;
public:
Student(): name(),rNo(0),CGPA(0),noOfCourses(0),courseList(50) {}
Student(string n,int r): name(n),rNo(r),CGPA(0),noOfCourses(0),courseList(50) {}
void printStudent() { cout << "Name : " << name << " " << "Roll No: " << rNo << " " << "CGPA: " << CGPA << endl; if(noOfCourses !=0) printCourse(); }
int getRoll() { return rNo; }
void addCourse(Course c) {
if(noOfCourses < 50) {
courseList.insert(c);
noOfCourses++;
}
else throw COURSE_LIMIT_REACHED;
}
void removeCourse(Course c) {
if(noOfCourses != 0){
courseList.remove(c);
noOfCourses--;
}
else cout << "There are no Courses to be removed\n" << endl;
}
void printCourse() { cout << "Courses Taken\n\n"; courseList.printData(); }
double calCGPA() {
Course c;
double sum = 0;
for(int i=0;i<noOfCourses;i++){
c = courseList.getData(i);
sum = sum + c.getGPA();
}
CGPA = sum/noOfCourses;
return CGPA;
}
friend ostream& operator<< (ostream& out, const Student& student) { out << student.name << " " << student.rNo << endl; return out; }
bool operator <(Student s) { if (rNo < s.rNo) return true; else return false; }
bool operator >(Student s) { if ( rNo > s.rNo) return true; else return false; }
bool operator ==(Student s) { return (rNo == s.rNo); }
};
template <class T>
class ListIterator {
private:
OrderedList<T> &list;
int current;
ListIterator & operator =(const ListIterator & rhs);
public:
ListIterator(OrderedList<T> &l): list(l), current(0) { }
ListIterator(const ListIterator<T> &li): list(li.list), current(li.current) { }
void begin(){ current = 0; }
int getCurrent() { return current; }
void end() { current = list.currentSize; }
bool isStart() { return current == 0; }
bool isDone() { return current == list.currentSize; }
void next() {
if (!isDone()) current++;
else throw ILLEGAL_REFERNCE;
}
bool find(const T key) {
current = list.search(key);
if (current > -1) return true;
else return false;
}
T getData() { return (list.listArray[current]); }
void setData(const T value) { list.listArray[current]; }
void insertData(T value) { list.insert(value); }
void removeData(T value) { list.remove(value); }
void getCourse(Student s) { getCourse(s); }
void printData() { list.printData(); }
};
int main() {
OrderedList<Student> studentList(10);
Student s1("Hamza",12105092);
Student s2("Ahmad",12105081);
Student s3("Sherlock",12105032);
Student s4("Watson",12134989);
Student s5("Gary",12105042);
Student s6("Ali",3111111);
ListIterator<Student> studentIterator(studentList);
studentIterator.insertData(s1);
studentIterator.insertData(s2);
studentIterator.insertData(s3);
studentIterator.insertData(s4);
studentIterator.insertData(s5);
studentIterator.printData();
cout << endl;
studentIterator.removeData(s1);
cout << "List After Removing A Student\n" << endl;
studentIterator.printData();
cout << endl;
Course c1("CS102",3.44);
Course c2("CS101",3.11);
Course c3("MATH101",4);
s5.addCourse(c1);
s5.addCourse(c2);
s5.addCourse(c3);
studentIterator.setData(s5);
s5.removeCourse(c2);
cout << "After removing a course\n" << endl;
s5.printStudent();
bool store;
string name;
int rollNo;
cout << "Enter The Student's Name and Roll Number To Find If He's Present In The List\n";
cin >> name;
cin >> rollNo;
Student s7(name,rollNo);
store = studentIterator.find(s7);
if(!store) cout << "Student is not present in the list\n" << endl;
else cout << "Student is present\n" << endl;
s5.calCGPA();
s5.printStudent();
int index = 0;
cout << endl;
cout <<"Enter the Student's name and Roll No. Whose Course Details You Want To Know" << endl;
cin >> name;
cin >> rollNo;
Student s9(name,rollNo);
store = studentIterator.find(s9);
if(store)
cout << studentIterator.getData();
else
cout <<"Entered Roll Number Isn't Present In The List" << endl;
studentList.printData();
return 0;
}
|
|
|
|
|
IMO, You should insert into a list, not in to an iterator.
The iterator is (only) used for traversing the list; have a look at what STL does, the container is std::vector and its iterator is std::vector::iterator.
Ok, to answer the questions:
1. Yes, there should be a method (private) inside the Student class to iterator over the course.
2. the printCourse method should iterator over the courseList list.
3. the studentList should not have a "printData"; just iterate over over the Student and call printCourse for each student in the list.
...
YMMV
Good luck.
Max.
I'd rather be phishing!
|
|
|
|
|
Please see #4 here.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
I have a console application which calculates using formulas based on the inputs it is receiving every cycle in a particular frequency and gives dynamic output values based on its input variables and constants and so on. In short its a real time application.
This application was initially developed in Visual Studio 6.0 as c++ console application. Recently we converted it to Visual Studio 2008.
It was working fine in VS 6.0. But after conversion, some of the values shows -1.#J which seems like infinite values.
When I observed, it seems like certain calculations may result in divide by 0 or complex values like square root of a negative number and these values should show the value as -1.#J.
But I wonder how there was no such values in VS6.0 whereas VS2008 shows these junk values.
Please suggest me some ways of preventing it.
modified 10-Apr-14 7:56am.
|
|
|
|
|
Please show your code.
Everything is the code !
|
|
|
|
|
Please show your code.
Everything is in the code !
|
|
|
|
|
I am posting one of the functions used in the code. There are many functions similar to this in the entire application
int CONDENSER(float Fl,float Fv,float Rc,float Gain,float DesFp,float Htcfl,
float Htcmaxfl,float Tflsh,float Fc, float Cpcw,
float Cppl, float Cppv, float Cpov,float Cpol, float DesFc,
float Tcwi,float Tpfi,float Tc,float Lhpv,float Lhv,
float Condeff,float CondHtarea,float Ambhc,
float Ambhf, float Ambt,float Mhc, float Mhf,
float Tfmax, float Tcmax,float *Liquid, float *Vapor,int IL, int IV,int OV, int OL,int FN,int CN)
{
int J,N,K,TYPE;
float Fp,SYCOMP,SXCOMP,Heatin,Heatvap,Heatliq;
float Heatloss,Hg,Hc,DELT1,DELT2,A,B,DENOM,DELT,Heatout;
float DER,MAX,MIN,FLAG,P,I,PI;
// Amount of Vapor condensed [ L = ( 1 - V/F) * F ]
Fp = Fl + Fv;
*Liquid = Rc * Fp;
// By material balance
*Vapor = Fp - (*Liquid);
// Composition of Vapor in equilibrium with Liquid Y = K * X
SYCOMP = 1.0E-10;
for(J=Esim->COMPBEG;J<=Esim->COMPEND;J++)
{
Esim->SCOMP[J][OV] = Esim->NKVAL[J][FN]*Esim->NXS[J][FN];
SYCOMP = SYCOMP + Esim->SCOMP[J][OV];
}
// Condensation rate (PI Logic)
Esim->NS1DER[FN]= 1 - (SYCOMP);
P = Gain*Esim->NS1DER[FN];
I = Esim->NS1S[FN];
I = LIMIT01(I+Esim->NODEK7[FN]*Esim->NS1DER[FN]);
PI = LIMIT01(P+I);
Esim->NS1S[FN] = LAG(PI,Esim->NS1S[FN],0.05);
Esim->NS1S[FN] = LIMIT01(Esim->NS1S[FN]);
// Condensed Liquid Composition
// FEED * Yi - VAP * Yi - LIQ * Xi = ACC * (d(Xi)/dt)*dt
// d(Xi) = (FEED * Yi - VAP * Yi - LIQ * Xi)/(ACC * dt)
SXCOMP = 1.0E-10;
for(J=Esim->COMPBEG;J<=Esim->COMPEND;J++)
{
Esim->SCOMP[J][OV] = Esim->SCOMP[J][OV]/SYCOMP;
Esim->NXDER[J][FN] = (Fl*Esim->SCOMP[J][IL]+Fv*Esim->SCOMP[J][IV] -(Fv)*Esim->NXS[J][FN]
-(Fl)*Esim->NXS[J][FN])/(10 + MAXI(Fp-(*Vapor),100.0)
*Esim->STPSIZEH/10000);
Esim->NXS[J][FN] = EULER( N, K, TYPE, DER, MAX, MIN, FLAG);
SXCOMP = SXCOMP + Esim->NXS[J][FN];
}
for(J=Esim->COMPBEG; J<=Esim->COMPEND; J++)
{
Esim->NXS[J][FN] = Esim->NXS[J][FN]/SXCOMP;
Esim->SCOMP[J][OL] = Esim->NXS[J][FN];
}
Hg = power((Fp/DesFp),0.5);
// Efficiency of the condenser
Esim->NS2[FN] = Condeff*MAXI(Htcfl*Hg,Htcmaxfl);
Esim->NHTR[FN] = Esim->NS2[FN]*(Tflsh - Tc);
if(Fc>0) // Cooling water side calculations
{
// From McCabe & Smith h=K*(Fc)**(-1/3)
Hc = power((Fc/DesFc),-0.33);
// Accounting for the overall Heat transfer coefficient
// 1/U = 1/Hg + 1/Hc
Esim->NS2[FN] = Condeff*CondHtarea*(Hg * Hc)/(Hg + Hc);
// Energy balance across the cooling node to find out temperature
// F*CP*(I/T-AMB)+HTRAN-F*CP*(O/T-AMB)-HLOSS = ACC*CP*(dT/dt)*dt
Esim->NTDER[CN]=(Heatin-Heatout)/(Mhc*Cpcw*Esim->STPSIZEH/10000);
} // Cooling water side calculations
Esim->STEMP[OV] = Esim->NTEMP[FN];
Esim->STEMP[OL] = Esim->NTEMP[FN];
Esim->SMFLOW[OV] = *Vapor;
Esim->SMFLOW[OL] = *Liquid;
return 0;
}
modified 10-Apr-14 8:26am.
|
|
|
|
|
Firstly, please indent your code properly and use <pre> tags around it so that it is readable, like:
for(J = Esim->COMPBEG; J <= Esim->COMPEND; J++)
{
Esim->SCOMP[J][OV] = Esim->SCOMP[J][OV]/SYCOMP;
Esim->NXDER[J][FN] = (Fl*Esim->SCOMP[J][IL]+Fv*Esim->SCOMP[J][IV] -(Fv)*Esim->NXS[J][FN]
-(Fl)*Esim->NXS[J][FN])/(10 + MAXI(Fp-(*Vapor),100.0)
*Esim->STPSIZEH/10000);
Esim->NXS[J][FN] = EULER( N, K, TYPE, DER, MAX, MIN, FLAG);
SXCOMP = SXCOMP + Esim->NXS[J][FN];
}
Secondly, please indicate exactly where the error occurs, and show the values of the inputs at the time.
|
|
|
|
|
You don't want to do that, you want to avoid device by zero period. If you don't know why, go back to school.
"The whole idea that carbon dioxide is the main cause of the recent global warming is based on a guess that was proved false by empirical evidence during the 1990s." climate-models-go-cold
|
|
|
|
|