
Newbie needs help with VC++ DLL
John,
At the C++ end:
extern "C" long WINAPI StringOp(LPSTR lpszString, long nSize)
{
CString csTest = "Hello world";
if (csTest.GetLength() <= nSize)
strcpy(lpszString, (LPCSTR) csTest);
return csTest.GetLength();
Quote:
}
Ensure StringOp is entered under the Declares section of the .def file.
VB end:
declare function StringOp lib "MyDll.dll"(byval lpszString$, byval nSize&)
as long
VB usage:
dim StrRet$
dim nRet&
StrRet$ = space$(100)
nRet& = StringOp(StrRet$, len(StrRet$))
if nRet& > len(StrRet$) then
StrRet$ = space$(nRet&+1)
nRet& = StringOp(StrRet$, len(StrRet$))
end if
StrRet$ = left$(StrRet$, nRet&)
Note that the string pointer is declared ByVal even though it is a pointer.
This is a language "feature" you just have to get used to <g>. Apparently
it instructs VB to convert the BSTR (which is what VB stores strings as) to
a LPSTR.
BTW untested code, so I hope not too many typos!
HTH
Peter Beach
Quote:
> I am trying to write a simple VC6++ DLL for hooking use by a VB6 app. I
have
> successfully created a DLL passing numeric data, but when I attempt any
> basic string manipulation (e.g. lstrcat(mystring, "XYZ")), my VB app GPFs
> every time. Severe loss of hair has resulted!
> Am I failing to include the necessary header files or allocate memory?
What
> data types - LPSTR/LPTSTR - Unicode or ANSI?
> Could a VC++ expert point me at a simple DLL that illustrates string
> manipulation.
> Many thanks,
> John Way