|
-
August 3rd, 2009, 09:45 AM
#7
Re: export from dll
1) I do this to understand Windows better, get experience in work with different kind of tools and so on. Also export from dll helps me to understand assembler. I'm not going to write code in assembler, as the process in not effective.
2) At the moment I have the following:
Code:
#include <windows.h>
//#include <wtypes.h>
#include <oleauto.h>
#include <stdlib.h>
#include <wctype.h>
#include <stdint.h>
#include <assert.h>
//----------------------------------------------------------------------------
char *allocate_bstr( const wchar_t *string )
{
int32_t length = wcslen( string );
char *result = (char *)malloc( 4 + length * 2 + 2 );
memcpy( result , &length , 4 );
memcpy( result + 4 , string , length * 2 );
memcpy( result + 4 + length * 2 , 0x0000 , 2 );
return result;
}
//----------------------------------------------------------------------------
int WINAPI WinMain( HINSTANCE hThisInstance,
HINSTANCE hPrevInstance,
LPSTR lpszCmdLine,
int nCmdShow )
{
typedef void (* procedure_type) ( BSTR arg_1 );
BSTR string = //(BSTR)allocate_bstr( L"I am a happy BSTR" );
SysAllocString( (const OLECHAR *)L"I am a happy BSTR" );
//NULL;
HMODULE module_handle = LoadLibrary( "msvbvm60.dll" );
assert( SUCCEEDED(module_handle) );
procedure_type procedure = (procedure_type)GetProcAddress( module_handle, "rtcMsgBox" );
assert( procedure != NULL );
procedure( string );
FreeLibrary( module_handle );
//free( string );
return 0;
}
This code compiles with (BSTR)allocate_bstr( L"I am a happy BSTR" ) and program fails with no msg box,
and the following compile time error occurs on MinGW 4.4.0,
Code:
C:\DOCUME~1\andrey\LOCALS~1\Temp\ccI7IhPE.o:loadlib.cpp:(.text+0x95): undefined reference to `SysAllocString@4'
collect2: ld returned 1 exit status
I've also tried procedure type with 2 argument with and without return value of type BSTR.
Last edited by andrey_zh; August 3rd, 2009 at 09:51 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|