Re: [Dev-C++] help needed with calling dll from Visual basic
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Per W. <pw...@ia...> - 2004-11-04 14:59:37
|
Your basic program have specified the parameter as ByVal. For a normal value this means that a copy of the variable is sent as a parameter, i.e. changes will not be reflected back. Since I don't program VB, I don't know the definition of ByVal for a pointer-type parameter. If it is the pointer that is ByVal or if it is the string. In case it's the string that is ByVal, it is obvious why you don't get a change in the VB program - the changes are only to a copy of the string and are immediately thrown away on return from the function. /Per W On Thu, 4 Nov 2004, Ni Jinfeng 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. > > > > 1. 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". > > > > 2. 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 > > > > > > |