Click to See Complete Forum and Search --> : VB (DLL) func -> VC func? Help please!


Hawk2k
September 23rd, 2001, 11:36 PM
Hello there! :-)

I've a big problem with a VB func out of a DLL. :-( I work on this now many weeks (with help from other programmers) without success. ;( The VB header for the func out of the DLL:

---cut---

'//////////////
'// LOADHULLKEYS
'// sPath : (input) is the complete path to the directory that has the ship packs
'// You need to supply sPath to LOADHULLKEYS
'//
'// vFistLong : (OUTPUT) is the first element in an array of 2000 longs
'// You must dim the array of 2000 longs and pass the first element
'// The array will be filled with a list of existing hull ID values
'// If element(23) of the array comes back with a value 23 then ship 23 exists
'// If element(23) comes back a zero the ship hull does not exist
'// If you Dim g_vList(1 to 2000) as long you MUST pass the element g_vList(1)
'//
'// sKey : (OUTPUT) This is a key string that LOADHULLKEYS returns to you.
'// Save this string and pass it to subs that require it as an input
'// This sub always loads the keys to the latest versions of the ship hulls, old ship files are ignored
Declare Sub LOADHULLKEYS Lib "v4face2.dll" (sPath as string, vFirstLong as Long, sKey as string)



---cut---

What I've (till now) works but the result vars are empty. What's wrong with this:


typedef DWORD dwat[2000];
typedef void (__stdcall* LOADHULLKEYS)(_bstr_t, dwat*, _bstr_t*);
LOADHULLKEYS _LoadHullKeys=NULL;



[...]

void LoadHullKeys(dwat* pdw_array, _bstr_t* p_bstr)
{
CString str=Planets4Path+_T("ships");
BSTR bstr=str.AllocSysString();

_LoadHullKeys(bstr, pdw_array, p_bstr);
}




p_bstr give nothing ("") back and the pdw_array is further filled with zero. :-(

[...]


typedef DWORD dwat[2000];
void LoadHullKeys(dwat*, _bstr_t*);



[...]

dwat dw_ar_result;
ZeroMemory(&dw_ar_result, sizeof(dwat));
_bstr_t BString;

LoadHullKeys(&dw_ar_result, &BString);




Another func out of this DLL works fine. Planets4Path is a pathstring (CString).

Help me please! Many thanks in advance!

Bye, ^Hawk^.

.-=> WWW: http://www.darksoft2001.de - ICQ: 129057905 <=-.

Andrew R.
September 27th, 2001, 06:49 PM
I've had the same problem: could not get string value from VB dll in VC project.
So I transfered string values through the VB global variables.
For example I had this function which didn't work:

public Fuction lGetName(byref strName_r as string) as Long
stName_r = "TestName"
lGetName = 0
End Function



I've replaced it with:

public Fuction lGetName() as Long
strName_m = "TestName"
lGetName = 0
End Function



and declared global variable in my class:

public strName_m as string



C++ creates wraper around such variables so you can use them.
Its ugly, but I couldn't find anything else.

Clearcode
September 28th, 2001, 03:56 AM
You probably need to allocate the space for the dll to write it's string into e.g.:


Dim sKey as string
Dim sPath as string

Dim pBuff(1 to 2000) as Long

sPath = string$(1024, 0)
sKey = string$(1024,0)

Call LOADHULLKEYS(sPath, pBuff(1), sKey)




HTH,
Duncan

-------------------------------------------------
Ex. Datis: Duncan Jones
Merrion Computing Ltd
http://www.merrioncomputing.com
Check out the new downloads - ImageMap.ocx is the VB control that emulates an HTML image map, EventVB.OCX for adding new events to your VB form and adding System Tray support simply, MCL Hotkey for implemenmting system-wide hotkeys in your application...all with source code included.