memory access violaton when call dll

Blitz3D Forums/Blitz3D Beginners Area/memory access violaton when call dll

Guan(Posted 2005) [#1]
I wrote a simple program to test the dll function, but each time got a memory violation warning.


The code in blitz3D:

bankin=CreateBank(6000)
bankout=CreateBank(6000)
CallDLL("TestDll","Test",bankin,bankout)

The code in VC for the DLL:

_declspec(dllexport) int _cdecl TestDll(const void *pIn,void *pOut)
{
*pOut=1;
return 1;

}

It seems the line "*pOut=1" caused the violation. Why?


Koriolis(Posted 2005) [#2]
1) If your function is named "TestDLL" Blitz will have a hard time finding it given that you're telling it to call a function named "Test". But that's not what is causing the MAV. I guess you jsut incorrectly copied your code in your post.
2) You need to declare the function as 'extern "C"'. Still not the reason for the MAV though
3) the signature of your function is wrong. It should be Test( const void *in,int in_size,void *out,int out_sz );
*this* is what causes your MAV, most probably.

You'd have spotted all of the above by yourself by just looking at the doc:
http://blitzbasic.com/b3ddocs/command.php?name=calldll&ref=goto

In addition I suggest you use userlibs instead of CallDLL:
http://blitzbasic.com/sdkspecs/sdkspecs/userlibs_specs.txt