Using DLLs

I am trying to use a dll in my program, but I cant figure out how to initialise it then use its functions in VC++.

I need something like (psuedocode)
load dll into memory;
use function 1;
use function 2;
release dll;

Can anyone help me?
pls try the function below:
LoadLibrary("dll file");
I got that part, but then the calling the functions part with GetProcAddress or whatever it is kept saying i had the wrong type of data and arguments and other stuff. What data types do I need for that?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <windows.h>

void main()
{
 HMODULE hMod=LoadLibrary("user32.dll");
 /////////////fisr method to invoke Api//////////////////////////
 int (__stdcall *MsgBox1)(HWND ,LPSTR,LPSTR,int);
 (FARPROC&)MsgBox1=GetProcAddress(hMod,"MessageBoxA");
 /////////////second method to invoke Api//////////////////////////
 typedef int (__stdcall *MSGBOX)(HWND ,LPSTR ,LPSTR ,INT); 
 MSGBOX MsgBox2=(MSGBOX)GetProcAddress(hMod,"MessageBoxA");
 
 MsgBox1(NULL,"first method succeed!\n\n"
  "1、int (__stdcall *MsgBox)(HWND ,LPSTR,LPSTR,int);\n"
  "2、(FARPROC&)MsgBox=GetProcAddress(hMod,\"MessageBoxA\");\n"
  "3、MsgBox(Null,\"hello,I love you\",\"Caption\",0);",
  "Invoke by function, Method 1:",0);

 MsgBox2(NULL,"second method succeed!\n\n"
  "1、typedef int (__stdcall *MSGBOX)(HWND ,LPSTR ,LPSTR ,INT);\n"
  "2、MSGBOX MsgBox2=(MSGBOX)GetProcAddress(hMod,\"MessageBoxA\");\n"
  "3、MsgBox2(Null,\"hello,I love you\",\"Caption\",0);",
  "Invoke by function pointer, Method 2:",0);

 return;
}

above is a sample for reference.
ok thankyou for that the loading now works.

now i have another problem

basically, the dll is a d3d wrapper for a program called game maker.

and all us people who use this dll are getting pissed off because game maker is so slow (about 10x slower than c++) . that is why i am trying to get it to work in c++.

when i call the dll's init function, the dll displays these messages:

Failed to create a direct3d 8.1 device.
Please make sure your color depth is set to 16 or 32 bit and try again.

Failed to initialise ultimate3d.


But the dll works fine in game maker. anyone know why this is happening and how to fix it?

Last edited on
Topic archived. No new replies allowed.