Memory Access Violation with CallDLL
Blitz3D Forums/Blitz3D Beginners Area/Memory Access Violation with CallDLL
| ||
It's been a while since I used Blitz3D but I am still suffering from the same problems. Since all these years I own Blitz3D (2003) I was never able to get CallDLL() running properly. I searched the forums but couldn't find a straight example demonstrating how to use this command. I mean an example wich is reproducable and not dependant from a specific library. Please someone have a look at this code: Graphics(420,320,0,2) SetBuffer(BackBuffer()) Function PokeString(Bank,Offset,Message$) Length = Len(Message$)-1 For i=0 To Length PokeByte(Bank,Offset + i,Asc(Mid(Message$,i+1,1))) Next End Function strHead$ = "Noitice" strBody$ = "This is a test string honkey!" hMemHead = CreateBank(Len(strHead$)) hMemBody = CreateBank(Len(strBody$)) PokeString(hMemHead,0,strHead$) PokeString(hMemBody,0,strBody$) hMemInput = CreateBank(16) PokeInt(hMemInput,00,0) ; hWnd : Handle to the owner window of the message box to be created PokeInt(hMemInput,04,hMemBody ) ; lpText : Pointer to a null-terminated string that contains the message to be displayed PokeInt(hMemInput,08,hMemHead) ; lpCaption : Pointer to a Null-terminated string that contains the dialog box title PokeInt(hMemInput,12,48) ; uType : Specifies the contents and behavior of the dialog box CallDLL("user32","MessageBoxA",hMemInput) Repeat : Cls : Flip : Until KeyDown(1) : End I appreciate any help on this issue. |
| ||
That's weird .. I don't understand it either. If you call the MessageBoxA without hMemInput, it does show a dialog, however empty offcourse. CallDLL("user32", "MessageBoxA") Have you looked at the .decls for user32 ? |
| ||
There is no .decl for this DLL since I believed API functions do not need this. |
| ||
It is in de code archives: http://www.blitzbasic.com/codearcs/codearcs.php?code=1179 The declaration for MessageBox is in there, too: api_MessageBox% (hwnd%, lpText$, lpCaption$, wType%) : "MessageBoxA" However, that still doesn't help much about why CallDLL doesn't work .. because I think it should. :/ |
| ||
CallDLL is for calling your own functions in your own dll, as the docs state the function prototype at the other end has to be in the form:extern "C"{ _declspec(dllexport) int _cdecl my_dll_func( const void *in,int in_size,void *out,int out_sz ); } Update your Blitz3D and use the new decls system if you want to call standard windows dll's and the like. |
| ||
CallDLL is for calling your own functions in your own dll... Well, that's not that case here. I am not calling my own function from my own DLL but an API function instead. ..as the docs state the function prototype at the other end has to be in the form ... Wich means what? The MessageBoxA / MessageBoxW functions don't have this particular form? Update your Blitz3D and use the new decls system if you want to call standard windows dll's and the like. Well, I'm already using the latest B3D version wich is v1.98 to my knowledge. Are you talking about the beta runtimes here? To sum this up, I would appreciate demo code showing me what I'm doing wrong considering that there is a flaw in my code. |
| ||
Wich means what? The MessageBoxA / MessageBoxW functions don't have this particular form? Correct, to call such functions you MUST use the userlibs system NOT calldll. http://blitzbasic.com/sdkspecs/sdkspecs/userlibs_specs.txt |
| ||
I assumed CallDLL to work with both, my fault then. So that means I have to declare the whole user32.dll into a Blitz userlib? I guess someone already did as well as for other libraries like shell32. |
| ||
No, you can also include only the messagebox declaration in the userlib, like this:.lib "user32.dll" api_MessageBox% (hwnd%.. etc Most declarations are in the code archive. Also, usually you can also do a search for the name of the .decls file in google, like "user32.decls". |
| ||
Thanks, I will give it a shot. |