Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with dll building

Status
Not open for further replies.

cucho

Programmer
Oct 1, 2001
15
AR
Hi,
i'm building a dll (with MFC) wich i need to call it from another language.
I declare it in this way
long __declspec(dllexport) __stdcall cfinterfase(CString h);

in the body of the function i need to concatenate 2 string 1 is the argument.

so i do this

long __declspec(dllexport) __stdcall cfinterfase(CString h)
{
CString d = "";
d = "hello " + h;
return 1;
}

i don't know why when it reach the concatenation it crashes and when i put to debug its points to the function memcpy()

Anybody knows why??

thanks.




 
I'm forget to mention that i'm using Visual C++ 6.0 without any sp or update.
 
memcpy is use for the = operator in the CString class and it's telling you that there is nothing to copy. I.E. CString h is null.

William
Software Engineer
ICQ No. 56047340
 
That sould read memcpy is used for ...

Also you won't see the result of the concatenation when the function completes since you are adding h to d, d will go out of scope when the function terminates.

Writing DLLs for VB can be a bit tricky due to the way data is passed.

HTH


William
Software Engineer
ICQ No. 56047340
 
f i do this i get
long __declspec(dllexport) __stdcall cfinterfase(CString h)
{
CString d = "HELLO: ";
AfxMessageBox(d);
AfxMessageBox(h);
return 10;
}

Its display 2 message box 1 with HELLO and the other with the value of h

but if i change the last afxmessagebox with
AfxMessageBox(d + h)
I get 2 messagebox with the word HELLO but the value of h i empty insteadof the HELLO + h


 
As I have already said the implication is that h is not getting passed to the function. At the top of the function enter the line
ASSERT(h != NULL) ;

in debug mode if h is null then the will give an assertion error, and point you in the direction of dodgy VB code.

You might also want to trace in to the DLL and put a watch in h to see what value if any is there.

You might also consider changing the declaration of the parameter to a const char*. Because at present it is in fact expecting a CString object that VB (AFAIK) does not have.

The same applies to d change it to a char* as well.

char d[12] = "Hello " ; //Make the buffer the size you need.
strcat(d, h) ;
AfxMessageBox(d) ;


William
Software Engineer
ICQ No. 56047340
 
As I have already said the implication is that h is not getting passed to the function. At the top of the function enter the line
ASSERT(h != NULL) ;

in debug mode if h is null then the will give an assertion error, and point you in the direction of dodgy VB code.

You might also want to trace in to the DLL and put a watch in h to see what value if any is there.

You might also consider changing the declaration of the parameter to a const char*. Because at present it is in fact expecting a CString object that VB (AFAIK) does not have.

The same applies to d change it to a char* as well.

const char* h = {"You to"} ; // Really from VB APP.
char d[12] = "Hello " ; //Make the buffer the size you need.
strcat(d, h) ;
AfxMessageBox(d) ;

HTH

William
Software Engineer
ICQ No. 56047340
 
As I have already said the implication is that h is not getting passed to the function. At the top of the function enter the line
ASSERT(h != NULL) ;

in debug mode if h is null then the will give an assertion error, and point you in the direction of dodgy VB code.

You might also want to trace in to the DLL and put a watch in h to see what value if any is there.

You might also consider changing the declaration of the parameter to a const char*. Because at present it is in fact expecting a CString object that VB (AFAIK) does not have.

The same applies to d change it to a char* as well.

const char* h = {"There!"} ; // Really from VB APP.
char d[16] = "Hello " ; //Make the buffer the size you need.
strcat(d, h) ;
AfxMessageBox(d) ;

HTH

William
Software Engineer
ICQ No. 56047340
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top