Gamestudio Links
Zorro Links
Newest Posts
Help with plotting multiple ZigZag
by degenerate_762. 04/30/24 23:23
M1 Oversampling
by 11honza11. 04/30/24 08:16
Trading Journey
by howardR. 04/28/24 09:55
Zorro Trader GPT
by TipmyPip. 04/27/24 13:50
Data from CSV not parsed correctly
by jcl. 04/26/24 11:18
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
4 registered members (7th_zorro, Ayumi, AndrewAMD, Quad), 1,014 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
firatv, wandaluciaia, Mega_Rod, EternallyCurious, howardR
19050 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Error implementing callback from DLL #325768
05/28/10 00:56
05/28/10 00:56
Joined: Oct 2006
Posts: 36
BigM Offline OP
Newbie
BigM  Offline OP
Newbie

Joined: Oct 2006
Posts: 36
Hello all,

I'm developing a DLL (in C++) that exports a function which is then called from lite-C. In the minimum working example below the only argument to the function is a pointer back to a lite-C callback function.

Puzzlingly, I get a run time error at the end of main, after all functions have returned. Here's the code:

Code:
//************** TesdDll.dll
#include "stdafx.h"
#include <Windows.h>
typedef void __stdcall callback(void);

extern "C" __declspec(dllexport) void fnTesdDLL(callback* cback){
	MessageBox(NULL, "We're in!", "TestDLL.dll",0);
	(*cback)();
}

//************** main.c
#include <acknex.h>
#include <windows.h>
void __stdcall fnTesdDLL(void*);
#define PRAGMA_API fnTesdDLL;TesdDLL!fnTesdDLL

void __stdcall cbk(){
	MessageBox(NULL, "We're back", "cbk",0);
}

void main(){
	fnTesdDLL(cbk);
	MessageBox(NULL, "We're in main", "main",0);
}



As you can see, I inserted some calls to MessageBox for debugging purposes. All three MessageBox calls are executed, the error surfacing only at the end of main().

The actual error (E1513) reads "Crash in SYS". Before I updated to the latest lite-C version the error read "Crash in cbk". Indeed, the problem seems to have something to do with the return from the callback: if I call fnTesdDLL(cbk) from within a function X then the error will pop at the end of X, not main.

Can anyone help?

Re: Error implementing callback from DLL [Re: BigM] #325824
05/28/10 14:38
05/28/10 14:38
Joined: Dec 2006
Posts: 1,086
Queensland - Australia
Nidhogg Offline
Serious User
Nidhogg  Offline
Serious User

Joined: Dec 2006
Posts: 1,086
Queensland - Australia
This might be better of in Higher languages forum


Windows XP SP3
Intel Dual Core CPU: E5200 @ 2.5GHz
4.00GB DDR3 Ram
ASUS P5G41T-M LX
PCIE x16 GeForce GTS 450 1Gb
SB Audigy 4
Spyware Doctor with AntiVirus
Re: Error implementing callback from DLL [Re: Nidhogg] #325855
05/28/10 17:32
05/28/10 17:32
Joined: Nov 2007
Posts: 1,143
United Kingdom
DJBMASTER Offline
Serious User
DJBMASTER  Offline
Serious User

Joined: Nov 2007
Posts: 1,143
United Kingdom
Hi, I've looked at your code and the problem seems to be the function prototype for the DLL function. Change this...
Code:
void __stdcall fnTesdDLL(void*);
#define PRAGMA_API fnTesdDLL;TesdDLL!fnTesdDLL


to simply this...
Code:
function fnTesdDLL(void*);


I have tested myself using my own callbacks and using your prototype singature gave me the crash. Use the lite-c function type.

Re: Error implementing callback from DLL [Re: DJBMASTER] #326186
05/30/10 23:03
05/30/10 23:03
Joined: Oct 2006
Posts: 36
BigM Offline OP
Newbie
BigM  Offline OP
Newbie

Joined: Oct 2006
Posts: 36
Thanks a lot for looking into it, DJBMASTER.

However, your solution did not work for me: I would always get "Empty prototype called in main".

I did get it to work by reading the manual blush blush
The case is well documented and has only to do with the use of __stdcall: because the DLL exported function is not also __stdcall the stack gets messed up.


Cheers

Re: Error implementing callback from DLL [Re: BigM] #326198
05/31/10 01:48
05/31/10 01:48
Joined: Nov 2007
Posts: 1,143
United Kingdom
DJBMASTER Offline
Serious User
DJBMASTER  Offline
Serious User

Joined: Nov 2007
Posts: 1,143
United Kingdom
hmm that may have been why just using 'function' worked in my case. This was my dll function...
Code:
typedef void __stdcall callback(void);
...
DLLFUNC void TestFunction(callback* c)
{
	(*c)();
}


without all the 'extern' stuff.

Last edited by DJBMASTER; 05/31/10 01:49.

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1