Click to See Complete Forum and Search --> : dll


ikcha
September 17th, 2007, 02:37 PM
this exported works in vb6. it probably works in c++ if <windows.h> is included. is it possible to make it work in c++ Exe without <windows.h>.
BSTR __declspec(dllexport) CALLBACK StringTest(BSTR StrVal)
{
char Str[100];
//fill Str with StrVal, do other things
char *Ret = Str;
return SysAllocString((BSTR)Ret);
}

JamesSchumacher
September 17th, 2007, 03:12 PM
// Answer is NO, reason is below
// LoadLibrary would be required and that requires <windows.h>

typedef BSTR (APIENTRY * PFN_SysAllocString)(const OLECHAR *);

HANDLE hLibrary = ::LoadLibrary("oleaut32.dll");

if (hLibrary != 0)
{
PFN_SysAllocString pfnFunc = (PFN_SysAllocString)::GetProcAddress(hLibrary,"SysAllocString"); // "SysAllocStringW" "SysAllocStringA" ?

if (pfnFunc != 0)
{
BSTR bStr = (*pfnFunc)(oleCharPointer);
}
}

::FreeLibrary(hLibrary);