Re: [Dev-C++] help needed with calling dll from Visual basic
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Cary H. <xen...@gm...> - 2004-11-04 15:11:13
|
I'm not an expert at this, but here are a few ideas I had: 1. since you are passing a pointer, the parameter is passed by reference, not by value. This might explain why the function seems to work, but doesn't actually change the string, as ByVal causes the function to create a copy of the string and performs its work on the copy, leaving the original intact. So, try ByRef instead of ByVal 2. since c treats strings as character arrays, you might want to try using that as the parameter, as VB might treat strings differently than character arrays. 3. try using fastcall instead of stdcall. Again, these are just ideas. Good luck! On Thu, 4 Nov 2004 08:11:10 -0600, Ni Jinfeng <ni_...@ba...> wrote: > > > > Hi, All. > > > > I am writing to ask for help from the Dev-C++ user community with the > problem of calling dll from visual basic. > > > > I wrote a dll by using Dev-C++ and the dll works fine with an interface > written in Dev-C++. However, when I tried to call the dll from an interface > written in visual basic, I run into problem. > > > > The dll contains a function with prototype shown below. It concatenates the > time to the string "name". > > > > Void reportTime (char *name); > > > > I call the function in dll from visual basic by using the > following declare statement > > > > Private Declare Sub reportTime Lib "c:\dlltest-4\dlltest-4.dll" > (ByVal name As String) > > > > I get an error message "bad dll calling convention". > > > > So I made some change to the prototype of the function in dll by adding > _stdcall as shown below. > > > > Void _stdcall reportTime (char *name); > > > > The declare statement is the same in the visual basic interface. > > > > This time, I do not get the error message shown above and I can tell that > the string "name" is passed into dll and the function can concatenate the > time to the string. However, after the dll returns the control back to the > interface, the string "name" in the interface does not reflect the > manipulation done in dll. I do not know what to do. > > > > Thank you in advance for your time and help. > > > > Jean Ni > > > > |