PureBASIC .lib files
PureBASIC .lib files
Hi,
When I create a new DLL using PureBASIC, it also create 2 other files.
I'd like to know if the generated .LIB file is compatible with VS 2005 ?
Thank you
Freddix
When I create a new DLL using PureBASIC, it also create 2 other files.
I'd like to know if the generated .LIB file is compatible with VS 2005 ?
Thank you
Freddix
So, yes. They are compatible...PureBasic DLL Sample wrote:;
; ------------------------------------------------------------
;
; PureBasic - DLL example file
;
; (c) 2002 - Fantaisie Software
;
; ------------------------------------------------------------
;
; This example is a skeleton to build easely a DLL using PureBasic
; The dll is created in the 'Compilers' directory, under the
; 'purebasic.dll' name. An associated '.lib' is generated to use
; with LccWin32 or VisualC++.
;
;
; Rules to follow:
; - Never write code outside a procedure, except for variables
; or structure declaration.
;
; - DirectX Init routines must not be initialized in the the
; AttachProcess() procedure
;
; - There is 4 procedures automatically called: AttachProcess(),
; DetachProcess(), AttachThread() and DetachThread(). If you don't
; need them, just remove them.

Windows 7 & PureBasic 4.4
compile this to "PBdll.dll"
make a new vc win32 console project, call it "PB dll test"
use notepad to save this as "PB dll test.c" and place it into the project folder, add the file to your project, (project/Add Existing Item)
put "PBdll.lib" into project folder and the dll in the app's path
follow the tip in the C file to add the lib to your project.
Code: Select all
ProcedureDLL.l IsPowerOf2(x.l)
t.l=0
If (x&(x-1))=0
t=1
EndIf
ProcedureReturn t
EndProcedure
ProcedureDLL.l IsPowerOf(power.l, base.l)
Protected basePow.l
Protected count.l
If base < 0 Or power < 0
ProcedureReturn -1
EndIf
If base = 0
If power = 1
ProcedureReturn 0
Else
ProcedureReturn 1
EndIf
EndIf
If base = 1
If power = 1
ProcedureReturn 1
Else
ProcedureReturn -1
EndIf
EndIf
If power = 1
ProcedureReturn 0
EndIf
basePow = base
While $7FFFFFFF / basePow > 1
count+1
If basePow = power
ProcedureReturn count
EndIf
basePow * base
Wend
ProcedureReturn -1
EndProcedure
ProcedureDLL.s Round2n(n.f,places.l)
If places < 0 : places = 0 : EndIf
r.f = 0.5 * Pow(10,-1*places) : T.f = Pow(10,places)
ProcedureReturn StrF(Int((n+r)*T)/T,places)
EndProcedure
use notepad to save this as "PB dll test.c" and place it into the project folder, add the file to your project, (project/Add Existing Item)
put "PBdll.lib" into project folder and the dll in the app's path
follow the tip in the C file to add the lib to your project.
Code: Select all
/*<note>
in project properties,
expand linker, click on commandline,
add: full path \PBdll.lib
example: "C:\Documents and Settings\John Doe\My Documents\Visual Studio 2005\Projects\PB dll test\pbdll.lib"
*/
#include <stdio.h>
extern __declspec(dllimport) int __stdcall IsPowerOf2(int n);
extern __declspec(dllimport) int __stdcall IsPowerOf(int power, int base);
extern __declspec(dllimport) char* __stdcall Round2n(float n,int places);
void main()
{
char ch;
int n,m;
n=IsPowerOf2(33);
m=IsPowerOf(49,7);
printf("%d\n",n);
printf("%d\n",m);
printf("%s\n",Round2n((float) 3.1415927,4));
printf("%s\n","press return to end");
ch=getchar();
}
Thank you for this great sample 
Do you think the declarations :
Another question now,
Is it possible to use existing .lib files from PureBASIC ?
Thank you.

Do you think the declarations :
Can be moved in an include file like :extern __declspec(dllimport) int __stdcall IsPowerOf2(int n);
extern __declspec(dllimport) int __stdcall IsPowerOf(int power, int base);
extern __declspec(dllimport) char* __stdcall Round2n(float n,int places);
?#include <MyInclude.h>
Another question now,
Is it possible to use existing .lib files from PureBASIC ?
Thank you.
If a function is a .lib return a value, etc .. Should I declare it in the import or will the importer detect it ?
For example in the .h file associated to the .lib I have this definition :
For example in the .h file associated to the .lib I have this definition :
Should I do this ? :int dbChecklistQuantity ( void );
Or Simply this and compiler will detect the returned value :Import
Retour.l = dbChecklistQuantity()
EndImport
Import
dbChecklistQuantity()
EndImport
>> Or Simply this
yes
Returnvalue is always a long!
yes

Returnvalue is always a long!
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.

Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
