dev-C++ dll howto
-
- Enthusiast
- Posts: 746
- Joined: Fri Jul 14, 2006 8:53 pm
- Location: Malta
- Contact:
dev-C++ dll howto
Folks,
I have some C functions I want to use in PB 4. But any dll I make I get invalid memory access.
this is a simple C code
#define API __stdcall
DLLIMPORT void API helloworld ( void )
{
MessageBox (0, "Hello World from DLL!\n", "Hi", MB_ICONINFORMATION);
}
and in PB
OpenLibrary(0, "arrays.dll")
helloworld = GetFunction(0, "helloworld")
CloseLibrary(0)
CallCFunctionFast(helloworld)
any ideas what I am doing wrong ?
cheers
KingLestat
I have some C functions I want to use in PB 4. But any dll I make I get invalid memory access.
this is a simple C code
#define API __stdcall
DLLIMPORT void API helloworld ( void )
{
MessageBox (0, "Hello World from DLL!\n", "Hi", MB_ICONINFORMATION);
}
and in PB
OpenLibrary(0, "arrays.dll")
helloworld = GetFunction(0, "helloworld")
CloseLibrary(0)
CallCFunctionFast(helloworld)
any ideas what I am doing wrong ?
cheers
KingLestat
-
- Enthusiast
- Posts: 746
- Joined: Fri Jul 14, 2006 8:53 pm
- Location: Malta
- Contact:
-
- Enthusiast
- Posts: 746
- Joined: Fri Jul 14, 2006 8:53 pm
- Location: Malta
- Contact:
-
- Enthusiast
- Posts: 746
- Joined: Fri Jul 14, 2006 8:53 pm
- Location: Malta
- Contact:
this is my test code with some forum help
OpenLibrary(0, "msvcrt.dll")
sprintf = GetFunction(0, "sprintf")
CloseLibrary(0) <-- this should not be here
OpenLibrary(0, "arrays.dll")
helloworld = GetFunction(0, "helloworld")
;CloseLibrary(0)
a = 5
n = @"A: %d"
buffer.s = Space(50)
CharsWritten = CallCFunctionFast(sprintf, buffer, n, a)
CallCFunctionFast(helloworld)
Debug buffer
Debug CharsWritten
Debug Len(buffer)
CloseLibrary(0)
OpenLibrary(0, "msvcrt.dll")
sprintf = GetFunction(0, "sprintf")
CloseLibrary(0) <-- this should not be here
OpenLibrary(0, "arrays.dll")
helloworld = GetFunction(0, "helloworld")
;CloseLibrary(0)
a = 5
n = @"A: %d"
buffer.s = Space(50)
CharsWritten = CallCFunctionFast(sprintf, buffer, n, a)
CallCFunctionFast(helloworld)
Debug buffer
Debug CharsWritten
Debug Len(buffer)
CloseLibrary(0)
Re: dev-C++ dll howto
In pb V5.60:
__________________________________________________
Code tags added
17.06.2017
RSBasic
Code: Select all
EnableExplicit
Define lib.l, a.i, n.s, buffer.s, CharsWritten.i
lib = OpenLibrary(#PB_Any, "msvcrt.dll")
PrototypeC.i ProtoSprintf(Buffer.s, Format.s, Arg1.l = 0, Arg2.l = 0, Arg3.l = 0, Arg4.l = 0)
Global sprintf.ProtoSprintf = GetFunction(lib, "swprintf")
CloseLibrary(lib)
a = 5
n = "About: %d"
buffer = Space(50)
CharsWritten = sprintf(buffer, n, a)
Debug buffer
Debug CharsWritten
Debug Len(buffer)
Code tags added
17.06.2017
RSBasic