Passing a string from a C++ DLL to VB
-
Hi All I'm trying to return a string from a dll to VBA as a BSTR but the variable always returns a null. What am I doing wrong? Are the variables passing out of scope before the result is returned?
#include #include #include BSTR __stdcall SomeFunction(LPSTR cSPC) CHAR cTheString [255]; BSTR bResult; UINT iStringsLength=0; strcmp(cSPC,"Absolute Return"); iStringsLength = strlen(cTheString); bResult = SysAllocStringByteLen(cTheString,iStringsLength); return bResult; }
The project builds, links and compiles successfully. Any thoughts about the problem would be gratefully accepted. Regards Jeremy -
Hi All I'm trying to return a string from a dll to VBA as a BSTR but the variable always returns a null. What am I doing wrong? Are the variables passing out of scope before the result is returned?
#include #include #include BSTR __stdcall SomeFunction(LPSTR cSPC) CHAR cTheString [255]; BSTR bResult; UINT iStringsLength=0; strcmp(cSPC,"Absolute Return"); iStringsLength = strlen(cTheString); bResult = SysAllocStringByteLen(cTheString,iStringsLength); return bResult; }
The project builds, links and compiles successfully. Any thoughts about the problem would be gratefully accepted. Regards JeremyYour code post has got mangled up, but I have two comments. I don't see anywhere in your code that an assignment of a string of characters takes place to the variable, cTheString. Thats probably why no string shows up in your BSTR. I don't know a lot about BSTR types, but since you are making a call to SysAlloc.. to create the BSTR, I would seem to me that there must be a call to SysDealloc.. somewhere or the BSTR is going to leak. Just my musings. Try using the <pre> and </pre> tags to show your code better. Chris Meech I am Canadian. [heard in a local bar] Remember that in Texas, Gun Control is hitting what you aim at. [Richard Stringer] Nice sig! [Tim Deveaux on Matt Newman's sig with a quote from me]
-
Hi All I'm trying to return a string from a dll to VBA as a BSTR but the variable always returns a null. What am I doing wrong? Are the variables passing out of scope before the result is returned?
#include #include #include BSTR __stdcall SomeFunction(LPSTR cSPC) CHAR cTheString [255]; BSTR bResult; UINT iStringsLength=0; strcmp(cSPC,"Absolute Return"); iStringsLength = strlen(cTheString); bResult = SysAllocStringByteLen(cTheString,iStringsLength); return bResult; }
The project builds, links and compiles successfully. Any thoughts about the problem would be gratefully accepted. Regards JeremySorry Chris - I copied out part of the code incorrectly here is what it should have been - Thanks Jeremy BSTR __stdcall SomeFunction(LPSTR cSPC) CHAR cTheString [255]; BSTR bResult; UINT iStringsLength=0; strcpy(cTheString,"Absolute Return"); iStringsLength = strlen(cTheString); bResult = SysAllocStringByteLen(cTheString,iStringsLength); return bResult; }