cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Return String from DLL?

unknown1
1-Newbie

Return String from DLL?

My code looks like this.........

if ( !adept_dll)

{
response("Couldn't load dll" . adept_dll_name);
return 0;
}


local sym = dl_find(adept_dll, "GetString")
if (!sym)
{
response("Couldn't find symbol " . name);
return 0;
}
local m_string = pack("p")

dl_call( sym, m_string )
# the signature of GetString is GetString ( char*
astring)
# To show that I have the string.
# Also how can I display this string
# in a messagebox.
message "$m_string"

dl_unload ( adept_dll )

The error I get is Adept : SegmentViolation( signal 11 )

I can trace the dll and see that the astring parameter is being filled
with the correct string.
1 REPLY 1

Hello John,

There are a couple potential problems. If you are using MFC then you will
need to include the following macro
AFX_MANAGE_STATE(AfxGetStaticModuleState()) in the exported function call
and declare with the __stdcall calling type:

extern "C" DllExport void* __stdcall GetString( char*

astring)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
}

Also in the pseudo code you provided you are not passing the pack function
any data. Here is a simple example which passes string data from Adept to
the DLL and returns a string to Adept.

The DLL Code:

extern "C" DllExport const char* __stdcall test( char* input_string)
{
//Macro always needs to be included in exported functions
AFX_MANAGE_STATE(AfxGetStaticModuleState());
LPCTSTR temp = "Output data to Adept";
return temp;
}

The ACL Code:

#for capturing return of the dll
global dll_return;

function test()
{
#get the function handle
local funct = dl_find( ddp_dll, "test");

#set string to a variable
local temp = "Input data to the DLL";

#pack the pointer of the temp variable
local temp_buf = pack( "p", temp);

#call function with parameters
local ret_value = dl_call( funct, temp_buf);

#get the pointer to the return value
#the receiving variable needs to be global
dll_return = unpack( "p", ret_value);

#show what was returned
response( dll_return);
}

Hope this helps,

Tim
Announcements