CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: dll

  1. #1
    Join Date
    Aug 2007
    Posts
    19

    dll

    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>.
    Code:
    BSTR __declspec(dllexport) CALLBACK StringTest(BSTR StrVal)
    {
    	char Str[100];
    	//fill Str with StrVal, do other things
    	char *Ret = Str;
    	return SysAllocString((BSTR)Ret);
    }

  2. #2

    Re: dll

    Code:
    // 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);

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured