Page 1 of 1
How to use generated .lib with dll creation?
Posted: Sat Jan 31, 2004 3:12 pm
by BalrogSoft
Hi, i tryed to use .lib generated file of DLL purebasic example, and i cant make it work, i copyed the dll to System directory, and i used Visual C++, Dev-C++, and Lcc, and dont work, on lcc exist an editor with an option to import foreign library, it says that cant find dll name, and copying .lib directly to lib directory of lcc gets this error when you use the EasyRequester function:
Warning d:\programaciom\lcc\projects\default\ei.c: 99 missing prototype for EasyRequester
Error d:\programaciom\lcc\projects\default\ei.c 99 undefined reference to _EasyRequester
search
Compilation + link time:0.6 sec, Return code: 1
You must declare the function before use or anything similar? or whats the trouble?
On Dev-C++ i got this error:
c:\mis documentos\untitled1.cpp: In function `int WinMain(HINSTANCE__ *, HINSTANCE__ *, CHAR *, int)':
c:\mis documentos\untitled1.cpp:54: implicit declaration of function `int EasyRequester(...)'
I dont know how to make work a library maded on PB with generated .exp or .lib files... Somebody can help me? because i tryed to use LoadLibrary and GetProcAddress API functions directly on C++ to call the library, but how to call the function after use this functions?
Posted: Sun Feb 01, 2004 10:44 am
by Seldon
The .LIB files are used so you don't need to declare the functions in your source and your DLL is added to your program at load-time.
The format used by PB, should be the same used by LCC (lcclnk) , so if you use LCC, just add your .LIB as an option for "lcclnk": when you link your C object:
lcclnk your_c_program.o your_pb_dll.lib
It should work.
With LCC, you can also declare a DLL function in your source, so you don't need to link the .LIB file, in this way:
Code: Select all
//Declaration:
int _stdcall (*your_Function) (char *, int, int); //change parameters according to your needs ! :-)
//Load the function:
*(void**)&your_Function=(FARPROC)GetProcAddress(LoadLibrary("your_dll.dll"),"your_Function");
I think VisualC and and Dev-C use a different .LIB format (I am not sure though) so you need to use a format converter or declare the functions at run-time as I showed you above.
Posted: Sun Feb 01, 2004 1:55 pm
by BalrogSoft
Hi, thanks to answer my question, but i cant made work... on LCC i can use "lcclnk your_c_program.o your_pb_dll.lib" because when i try to compile object it says that prototype of EasyRequester isnt found and the object wasnt created and i cant to use lcclnk without an object file, and trying to use dll directly as you say, dont work on lcc, or dev-c or VC++, with dev-c it crash on the moment that i use LoadLibrary, and i think that your form to call libraries works with Dev-C but it crash... its strange, it works with another api32 dll libs, but not with PB Dlls...
This is the c code for Dev-c++ that i used:
Code: Select all
#include <windows.h>
LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdShow)
{
static TCHAR szAppName[] = TEXT ("HelloWin") ;
HWND hwnd ;
MSG msg ;
WNDCLASS wndclass ;
wndclass.style = CS_HREDRAW | CS_VREDRAW ;
wndclass.lpfnWndProc = WndProc ;
wndclass.cbClsExtra = 0 ;
wndclass.cbWndExtra = 0 ;
wndclass.hInstance = hInstance ;
wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION) ;
wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ;
wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ;
wndclass.lpszMenuName = NULL ;
wndclass.lpszClassName = szAppName ;
if (!RegisterClass (&wndclass))
{
MessageBox (NULL, TEXT ("This program requires Windows NT!"),
szAppName, MB_ICONERROR) ;
return 0 ;
}
hwnd = CreateWindow (szAppName, // window class name
TEXT ("Test"), // window caption
WS_OVERLAPPEDWINDOW, // window style
CW_USEDEFAULT, // initial x position
CW_USEDEFAULT, // initial y position
CW_USEDEFAULT, // initial x size
CW_USEDEFAULT, // initial y size
NULL, // parent window handle
NULL, // window menu handle
hInstance, // program instance handle
NULL) ; // creation parameters
ShowWindow (hwnd, iCmdShow) ;
UpdateWindow (hwnd) ;
HINSTANCE hLibrary;
// Program crash here, try to change lib name with user32.dll and works ok
if ((hLibrary = LoadLibrary (TEXT ("purebasic.dll"))) == NULL)
{
MessageBox (hwnd, TEXT ("Can't load purebasic.dll."),
szAppName, 0) ;
return -1 ;
}
while (GetMessage (&msg, NULL, 0, 0))
{
TranslateMessage (&msg) ;
DispatchMessage (&msg) ;
}
return msg.wParam ;
}
LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
HDC hdc ;
PAINTSTRUCT ps ;
RECT rect ;
switch (message)
{
case WM_CREATE:
return 0 ;
case WM_PAINT:
hdc = BeginPaint (hwnd, &ps) ;
GetClientRect (hwnd, &rect) ;
DrawText (hdc, TEXT ("Hello"), -1, &rect,
DT_SINGLELINE | DT_CENTER | DT_VCENTER) ;
EndPaint (hwnd, &ps) ;
return 0 ;
case WM_DESTROY:
PostQuitMessage (0) ;
return 0 ;
}
return DefWindowProc (hwnd, message, wParam, lParam) ;
}
Posted: Sun Feb 01, 2004 2:35 pm
by BalrogSoft
Hi... sorry for last post, it was a mistake that i maded, the problem, use attach and detach process procedures when are empty on DLL example, i deleted it, and now works peferctly, thanks Seldon, i will include on iCamPlay thanks, because i was trying to use my library on C++.