The Programm stopps immediately after starting in the IDE at the first "begin" of the dpr-File...
Main Topics
Browse All TopicsHello 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?
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Sorry I couldn't reply sooner, I saw your replies just now.
Strange indeed.... I copied your code exactely as is into D2007 (I don't have 2009 here). I had to add 2 lines into main.pas in order to compile:
implementation
{$R *.dfm}
In order to run I need the dll so I created a new dll (streams.dll) which exports a function SetCallback (which does nothing).
My test program compiles and runs just fine. Not sure if this helps you, but you should be able to repeat above steps....
I cant change the dll, because i dont have the source and also no c/c++ environment...
The two lines i have forgotten because this is only an example and not my real code...only important lines to understand my problem...
In the past i have also done callbacks from dll's which have worked, but this one is strange to me...
I dont know what i could do to figure out the problem.
It seems that the external procedure could not be loaded for some reason...
If you want i could send you the whole example with the dll (c++ example and my delphi code)...
When you link a DLL statically, the library will be loaded and initialized right when you launch your application, but no other function calls will be made to the dll so it shouldn't matter which exported functions your program is about to use, as long as they exists and are exported by the dll. Try this:
Create a new project with just a form and a button (do not include streamlib or anything else in this project). Copy Streams.dll to your project directory unless it is alredy in your OS search path. Add a button to Form1 with the following code:
procedure TForm1.Button1Click(Sender
var
AHandle: HInst;
begin
AHandle := LoadLibrary('Streams.dll')
GetProcAddress(AHandle, 'SetCallback');
FreeLibrary(AHandle);
end;
What happens? Does it crash on the line with LoadLibrary? If it does then something is wrong with the initialization code inside the DLL.
Your example with dynamically loading the lib function points me to the error...
Because the pointer which i got back for the function was NIL, i have seen that the name of the function was written wrong!!!
Instead of "SetCallback", i had to write "SetCallBack"...
I am sure i wasted another day before i had found this.
Before i have always statically implemented libraries...dynamically i have never done before...
Thanks for your help Jonas.
The points goes to you...i will mark your 3rd answer as solution, because it pointed me to the error....
Business Accounts
Answer for Membership
by: JonasMalmstenPosted on 2009-06-23 at 02:02:09ID: 24690106
I'm not sure I'm all clear about this, does the program crash right away when you launch it or after you click Button1 to register the callback?
If it is after you clicked Button1, place a breakpoint on begin right after MyCallback, does the program stop there then?
If it does stop there, try replacing MyCallback with this (maybe the DLL is calling the wrong type of function):
procedure MyCallback(pVideoInfo : Pointer; param : Cardinal); stdcall;
begin
end;