Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

A function in a DLL that returns a string

Status
Not open for further replies.

msdawy2

Programmer
Jan 8, 2004
10
0
0
EG
Hello,
I am trying to create a function in a DLL (using Visual C++) that returns a string, and then use it in Visual Basic.

I have never actually created a dll before, but after following a tutorial, i ended up with both sides compiling succesfully, but when i run the vb prog, Visual Basic, causes an illegal operation and closes..


Here is a quick insight...

Visual Basic Side:
--------------------
Option Explicit
Private Declare Function getSerial Lib "getProp.dll" (ByVal Drv As Integer) As String

Private Sub Command1_Click()
Text1.Text = getSerial(0)
End Sub

--------------that's all!
for the Visual C++ side...

CString serial[4]; //global array
CString _stdcall getSerial(int device)
{
FillValues();
return serial[device];
}


=====================
and then the def file
; getharddll.def : Declares the module parameters for the DLL.

LIBRARY "getprop"
DESCRIPTION 'Gets physical properties of hard drives'

EXPORTS
; Explicit exports can go here
getSerial




IS there anything wrong?
The important question is
can i return a CString in vC++ and receive it as a String in VB? are there any other solutions??

Thank you very much in advance...






 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top