Main forum > FAQ

How to wrap a DLL

<< < (2/4) > >>

Leos:
It's working, thank you!

Gary:
Could someone tell me where I am going wrong in this code? I thought I had followed all the example properly


--- Code: (glbasic) ---// --------------------------------- //
// Project: test
// Start: Tuesday, May 26, 2015
// IDE Version: 12.308


// SETCURRENTDIR("Media") // go to media files

INLINE
// A MessageBox wrapper

extern "C" { // it&#39;s a C linking, as dependency walker told us
DECLARE_ALIAS(exportMessageBoxA, "user32.dll", "MessageBoxA", (void*, const char*, const char*, unsigned int), int);
} // close the extern "C"

ENDINLINE

main:


FUNCTION Win32MessageBox: text$, caption$
INLINE // of course, GLBAsic does not know about "exportMessageBoxA" - only INLINE does
   if(exportMessageBoxA)
      return exportMessageBoxA(0, text_Str.c_str(), caption_Str.c_str(), 0);
ENDINLINE
ENDFUNCTION

FUNCTION main:
Win32MessageBox("Test\nText","Hello")
ENDFUNCTION
--- End code ---

but it compiles with these errors

C:\Users\Gary\AppData\Local\Temp\glbasic\gpc_temp0.cpp: In function `int __GLBASIC__::__MainGameSub_()':
C:\Users\Gary\AppData\Local\Temp\glbasic\gpc_temp0.cpp:65: error: expected unqualified-id before string constant
C:\Users\Gary\AppData\Local\Temp\glbasic\gpc_temp0.cpp: In function `DGInt __GLBASIC__::Win32MessageBox(__GLBASIC__::DGStr, __GLBASIC__::DGStr)':
C:\Users\Gary\AppData\Local\Temp\glbasic\gpc_temp0.cpp:175: error: `exportMessageBoxA' was not declared in this scope
*** FATAL ERROR - Please post this output in the forum

kanonet:
You either need to place this into a 2ndary gbas file, or you need to close GLBasic's main function. To do so, add a dummy GLBasic function before your INLINE code:

--- Code: (glbasic) ---FUNCTION Foo:
ENDFUNCTION

INLINE
// your stuff below here
--- End code ---
This rule applies to any INLINE code. Now try again. ;)

MrTAToad:
The code needs to be in a source file and not the main program.  The main function however, should be in the main program.

Gary:
cheers guys, thats got the example code running.

Im trying to wrap a 3rd party dll and have a few functions to add

the first one has no parameters passed to it but returns an int. I thought the code would be as follows


--- Code: (glbasic) ---INLINE


extern "C" { // it's a C linking, as dependency walker told us
DECLARE_ALIAS(BPConnect, "GameSocket.dll", "BP_Connect", (void*), int);
} // close the extern "C"
ENDINLINE

FUNCTION Connect:
INLINE
if(BPConnect)
return BPConnect();
ENDINLINE
ENDFUNCTION
--- End code ---

but this fails with the following error
compiling:
CMD: >>"C:\Program Files\GLBasic_v11\Compiler\platform\Win32\Bin\g++.exe" -B"C:\Program Files\GLBasic_v11\Compiler\platform\Win32\Bin" -pipe -O3 -w -c -x c++ -mwindows -I"C:\Program Files\GLBasic_v11\Compiler\platform\Include" -I"C:\Documents and Settings\Owner\Desktop\GL_DLL" -D_WINDOWS_ -DNDEBUG -DHAVE_OPENGL "C:\DOCUME~1\Owner\LOCALS~1\Temp\glbasic\gpc_tempg.cpp" "C:\DOCUME~1\Owner\LOCALS~1\Temp\glbasic\gpc_temp0.cpp" "C:\DOCUME~1\Owner\LOCALS~1\Temp\glbasic\gpc_temp1.cpp"    -DWIN32=1<<
C:\DOCUME~1\Owner\LOCALS~1\Temp\glbasic\gpc_temp1.cpp: In function `DGInt __GLBASIC__::Connect()':
C:\DOCUME~1\Owner\LOCALS~1\Temp\glbasic\gpc_temp1.cpp:42: error: too few arguments to function
*** FATAL ERROR - Please post this output in the forum

Any more tips?

I was given the following C code to connect the main functions

bool UnlimitedConnect(void)
{
   bool RetVal;
   bool connected;
   connected = false;
   DllModule = LoadLibrary( TEXT( "GameSocketDll.dll" ) );
   if (DllModule)
   {
       // Find all of the addresses
BP_StartDLL =(bp_bool_hwnd) GetProcAddress( DllModule, "BP_StartDLL" );
BP_EndDLL =   (bp_bool_void) GetProcAddress( DllModule, "BP_EndDLL" );
BP_Connect =   (bp_bool_void) GetProcAddress( DllModule, "BP_Connect" );
BP_Disconnect =   (bp_bool_void) GetProcAddress( DllModule, "BP_Disconnect" );
BP_EndGame =  (bp_bool_void) GetProcAddress( DllModule, "BP_EndGame" );
BP_UseCredit =   (bp_int_int) GetProcAddress( DllModule, "BP_UseCredit" );
BP_GetCredit =   (bp_int_bool) GetProcAddress( DllModule, "BP_GetCredit" );
BP_AddBank =   (bp_int_int) GetProcAddress( DllModule, "BP_AddBank" );
BP_GetBank =   (bp_int_bool) GetProcAddress( DllModule, "BP_GetBank" );
BP_PayoutAtLimit =   (bp_void_void) GetProcAddress( DllModule, "BP_PayoutAtLimit" );
BP_Payout =    (bp_bool_int) GetProcAddress( DllModule, "BP_Payout" );
BP_IsButtonDown =   (bp_bool_int) GetProcAddress( DllModule, "BP_IsButtonDown" );
BP_SetLamp =   (bp_void_int_bool) GetProcAddress( DllModule, "BP_SetLamp" );

       if (BP_StartDLL && BP_Connect)
       {
          RetVal = (*BP_StartDLL)(hWndThread);
          if (RetVal)
          {
             RetVal = (*BP_Connect)();
             if (RetVal)
             {
                 connected = true;
}
}
}
}
   return (connected);
}

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version