[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

6.6

c/c++ dll callback calling from delphi

Asked by richard_exchange in Pascal Programming Language, C++ Programming Language, Delphi Programming

Tags: DLL Delphi Callback

Hello experts,

i have a C/C++ dll which exports a function where i have to give a pointer to an callback procedure...
I am using Delphi2009.

This is the only function of the library which does not work...

The program stops at the first line ("begin" in the .dpr-File) of the code, and after
resume (f9) the following exception is shown:

      "access violation at 0x00407766: write of address 0x00040124...."

Other functions of the library are working fine. Only this callback doesn't work...
If i remove this line from the main code the program starts without error.

There must be something wrong in var convertion or parameter definition.
I have tried several versions to declare the procedure, but every time the same error...

Can anybody help, please?
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:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
188:
189:
190:
191:
192:
193:
194:
195:
196:
197:
198:
199:
200:
201:
202:
203:
204:
205:
206:
207:
208:
209:
210:
211:
212:
213:
214:
215:
216:
217:
218:
219:
220:
221:
222:
223:
224:
225:
226:
227:
228:
229:
230:
231:
232:
233:
234:
235:
236:
237:
238:
239:
240:
241:
242:
243:
244:
245:
246:
247:
248:
249:
250:
251:
252:
253:
254:
255:
256:
257:
258:
259:
260:
261:
262:
263:
264:
265:
266:
267:
268:
269:
270:
271:
272:
273:
274:
275:
276:
277:
278:
279:
280:
281:
282:
283:
284:
285:
286:
287:
288:
289:
290:
291:
292:
// stream.h definitions...
 
#define _HANDLE	int
 
//////////////////////////////////////////////
// Codec
//////////////////////////////////////////////
enum AUDIOCODEC
{
	AUDIO_CODEC_UNKNOWN,
	AUDIO_CODEC_G711_64K,
	AUDIO_CODEC_G726_40K,
};
 
enum VIDEOCODEC
{
	VIDEO_CODEC_UNKNOWN,
	VIDEO_CODEC_JPEG,
	VIDEO_CODEC_MPEG4,
};
 
////////////////////////////////////////////////////////////////////////////////
// S_ERROR
////////////////////////////////////////////////////////////////////////////////
enum S_ERROR
{
	S_OK					  	  = 0,
	S_ERR_PARAM	 			  = 400,			// Parameter error
	S_ERR_ALLOC					= 401,			// Failed to allocate memory
	S_ERR_VERSION				= 402			  // Failed to get the version information
};
 
//////////////////////////////////////////////
// Video/Audio codec
//////////////////////////////////////////////
struct VIDEOCODECINFO
{
	VIDEOCODEC		Codec;
	int				Width;
	int				Height;
};
struct AUDIOCODECINFO
{
	AUDIOCODEC		Codec;
	unsigned short  Channels;
  unsigned long	SamplesPerSec;
  unsigned short  BitsPerSample;
};
 
//////////////////////////////////////////////
// UserData
//////////////////////////////////////////////
struct USERDATA
{
	char			CamTim	[32];
	unsigned short	FrmRate;
	char			TimStamp[11];
};
 
//////////////////////////////////////////////
// Get Video/Audio data
//////////////////////////////////////////////
struct VIDEOINFO
{
	char			*pBuf;
	unsigned int	BufLen;
	VIDEOCODECINFO	VideoCodecInfo;
	USERDATA		UserData;
	bool			KeyFrame;
};
struct AUDIOINFO
{
	char			*pBuf;
	unsigned int	BufLen;
	AUDIOCODECINFO	AudioCodecInfo;
};
 
//////////////////////////////////////////////
// Call back
//////////////////////////////////////////////
typedef void (__stdcall *VCALLBACK )( VIDEOINFO *pVideoInfo, unsigned long Param );
typedef void (__stdcall *ACALLBACK )( AUDIOINFO *pAudioInfo, unsigned long Param );
typedef void (__stdcall *AVCALLBACK)( VIDEOINFO *pVideoInfo, AUDIOINFO *pAudioInfo, unsigned long Param );
 
enum CALLBACKTYPE
{
	CALLBACK_RAW_VIDEO,
	CALLBACK_RAW_AUDIO,
	CALLBACK_RAW_BOTH,
	CALLBACK_DEC_VIDEO,
	CALLBACK_DEC_AUDIO,
	CALLBACK_DEC_BOTH,
};
 
 
// The callback registering procedure...
 
S_ERROR __stdcall SetCallback( _HANDLE sHandle, CALLBACKTYPE callbackType, void* pCallbackFunction, unsigned long param );
 
================================================================================
//my library wrapper unit
 
unit StreamLib;
{$Z4,A4}
interface
 
uses Windows;
 
type
  _HANDLE = Integer;
 
//////////////////////////////////////////////
// Codec
//////////////////////////////////////////////
  _AUDIOCODEC = (
    AUDIO_CODEC_UNKNOWN,
    AUDIO_CODEC_G711_64K,
    AUDIO_CODEC_G726_40K
  );
  P_VIDEOCODEC = ^_VIDEOCODEC;
  _VIDEOCODEC = (
	  VIDEO_CODEC_UNKNOWN,
	  VIDEO_CODEC_JPEG,
	  VIDEO_CODEC_MPEG4
  );
 
//////////////////////////////////////////////
// S_ERROR
//////////////////////////////////////////////
  S_ERROR = (
    S_OK							    = 0,
    S_ERR_PARAM						= 400,			// Parameter error
    S_ERR_ALLOC						= 401,			// Failed to allocate memory
    S_ERR_VERSION					= 402			// Failed to get the version information
  );
 
//////////////////////////////////////////////
// Video/Audio codec
//////////////////////////////////////////////
  P_VIDEOCODECINFO = ^_VIDEOCODECINFO;
  _VIDEOCODECINFO = record
    Codec  : _VIDEOCODEC;
    Width  : Integer;
    Height : Integer;
  end;
  P_AUDIOCODECINFO = ^_AUDIOCODECINFO;
  _AUDIOCODECINFO = record
    Codec : _AUDIOCODEC;
    Channels : Word;
    SamplesPerSec : Cardinal;
    BitsPerSample : Word;
  end;
 
//////////////////////////////////////////////
// UserData
//////////////////////////////////////////////
  _USERDATA = record
	  CamTim : array[0..31] of AnsiChar;
	  FrmRate : Word;
	  TimStamp : array[0..10] of AnsiChar;
  end;
//////////////////////////////////////////////
// Get Video/Audio data
//////////////////////////////////////////////
  P_VIDEOINFO = ^VIDEOINFO;
  VIDEOINFO = record
    pBuf : PAnsiChar;
    BufLen : Cardinal;
    VideoCodecInfo : _VIDEOCODECINFO;
    UserData : _USERDATA;
    KeyFrame : Boolean;
  end;
  P_AUDIOINFO = ^AUDIOINFO;
  AUDIOINFO = record
    pBuf : PAnsiChar;
    BufLen : Cardinal;
    AudioCodecInfo : _AUDIOCODECINFO;
  end;
 
//////////////////////////////////////////////
// Call back
//////////////////////////////////////////////
VCALLBACK = procedure(pVideoInfo : P_VIDEOINFO; param : Cardinal); stdcall;
ACALLBACK = procedure(pAudioInfo : P_AUDIOINFO; param : Cardinal); stdcall;
AVCALLBACK = procedure(pVideoInfo : P_VIDEOINFO; pAudioInfo : P_AUDIOINFO; param : Cardinal); stdcall;
 
type
  CALLBACKTYPE =(
    CALLBACK_RAW_VIDEO,
    CALLBACK_RAW_AUDIO,
    CALLBACK_RAW_BOTH,
    CALLBACK_DEC_VIDEO,
    CALLBACK_DEC_AUDIO,
    CALLBACK_DEC_BOTH
  );
 
// Here the definition of the callback registering procedure, which does not work...
function SetCallback( Handle : _HANDLE; callbackType : CALLBACKTYPE; pCallbackFunction : pointer; param : Cardinal ) : S_ERROR; stdcall;
 
implementation
 
const
  myDLL = 'stream.dll';
 
function SetCallback;  external myDLL;
 
end.
 
==============================================================================
// Example Testprogram
 
unit Main;
 
interface
 
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  StreamLib;
 
type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private-Deklarationen }
    myHandle : Integer;
  public
    { Public-Deklarationen }
  end;
 
var
  Form1: TForm1;
 
 
// My Callback procedure to handle the frame...
procedure MyCallback(pVideoInfo : Pointer; pAudioInfo : Pointer; param : Cardinal); stdcall;
begin
  // ....
end;
 
procedure TForm1.Button1Click(Sender: TObject);
Var myErrorCode : S_ERROR;
begin
   // register the callback procedure...
   myErrorCode := SetCallback( myHandle, CALLBACK_RAW_BOTH, @MyCallback, 0 );
 
end;
 
end.
 
==================================================================================
 
Following are the debugging outputs:
 
Stack:
> :00407766 LoadResString + $E
  :00410abf GetExceptionObject + $57
  :00404181 @HandleAnyException + $35
  :7c91378b ntdll.RtlConvertUlongToLargeInteger + 0x46
  :7c91eafa ntdll.KiUserExceptionDispatcher + 0xe
  :7c91378b ntdll.RtlConvertUlongToLargeInteger + 0x46
  :00404224 @HandleAnyException + $D8
  :7c91378b ntdll.RtlConvertUlongToLargeInteger + 0x46
  :7c91eafa ntdll.KiUserExceptionDispatcher + 0xe
  :7e369dbb USER32.LoadCursorW + 0x52
  :7e369e4e USER32.LoadStringW + 0x18
  :004077a2 LoadResString + $4A
  :00410abf GetExceptionObject + $57
 
CPU:
  LoadResString:
  00407758 53               push ebx
  00407759 56               push esi
  0040775A 50               push eax
  0040775B B802000000       mov eax,$00000002
  00407760 81C404F0FFFF     add esp,$fffff004
> 00407766 50               push eax
  00407767 48               dec eax
 
Protokoll:
...
Modul laden: Camera.dll. Ohne Debug-Infos. Basisadresse: $004F0000. Prozess Test.exe (1984)
Modul laden: WS2_32.dll. Ohne Debug-Infos. Basisadresse: $71A10000. Prozess Test.exe (1984)
Modul laden: WS2HELP.dll. Ohne Debug-Infos. Basisadresse: $71A00000. Prozess Test.exe (1984)
Modul laden: UNKNOWN_MODULE_50. Ohne Debug-Infos. Basisadresse: $0A000000. Prozess Test.exe (1984)
Modul laden: PSAPI.DLL. Ohne Debug-Infos. Basisadresse: $76BB0000. Prozess Test.exe (1984)
Modul laden: NETAPI32.dll. Ohne Debug-Infos. Basisadresse: $597D0000. Prozess Test.exe (1984)
Modul entladen: UNKNOWN_MODULE_50. Prozess Test.exe (1984)
Modul entladen: NETAPI32.dll. Prozess Test.exe (1984)
Modul entladen: PSAPI.DLL. Prozess Test.exe (1984)
Modul laden: IMM32.dll. Ohne Debug-Infos. Basisadresse: $76330000. Prozess Test.exe (1984)
Modul laden: MSCTF.dll. Ohne Debug-Infos. Basisadresse: $746A0000. Prozess Test.exe (1984)
[+][-]06/23/09 02:02 AM, ID: 24690106Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06/23/09 02:04 AM, ID: 24690115Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06/23/09 02:06 AM, ID: 24690127Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06/23/09 02:30 AM, ID: 24690239Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06/23/09 02:58 AM, ID: 24690392Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06/23/09 07:46 AM, ID: 24692441Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06/23/09 07:59 AM, ID: 24692584Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06/23/09 08:47 AM, ID: 24693024Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zones: Pascal Programming Language, C++ Programming Language, Delphi Programming
Tags: DLL Delphi Callback
Sign Up Now!
Solution Provided By: JonasMalmsten
Participating Experts: 1
Solution Grade: A
 
[+][-]06/23/09 08:53 AM, ID: 24693087Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06/23/09 08:56 AM, ID: 24693119Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06/23/09 09:00 AM, ID: 24693166Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06/23/09 09:01 AM, ID: 24693175Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06/23/09 09:05 AM, ID: 24693227Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06/23/09 09:44 AM, ID: 24693597Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091111-EE-VQP-89 - Hierarchy / EE_QW_3_20080625