Log in

View Full Version : Problem in calling vc++ dll in vb.net


rakesh_mahajan
03-31-2006, 11:39 AM
I have created a win32 dll for pocket PC 2003.

I have written following function in the dll:

wchar_t* _stdcall testfunc (int i,int j,wchar_t* str)
{

int k = i;
k=j;
k=i+j;

wcscpy(str,_T("Some data"));
return str;

}


I am calling this dll from vb.net application

I am using following steps to call the function :

Public Declare Function testfunc Lib "test.dll" (ByVal a As
Integer, ByVal b As Integer, ByVal c As String) As String

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load


Dim bflag As Boolean
dim strret as string
databasefilename = "abc.txt"

strret = testfunc(2, 3, databasefilename)

End Sub


When i devbug my dll i am not able to get string value.
integer value is same what i am passing from function call.

What should be the problem?

I also tried using char* instead of wchar_t* but no luck.

I am stuck at this point.

Thanks,
Rakesh

gwinter
03-31-2006, 03:14 PM
I'm not familiar with VB.NET, but you have to check:

Public Declare Function testfunc Lib "test.dll" (ByVal a As Integer, ByVal b As Integer, ByVal c As String) As String
1. Make sure whether ByVal or ByRef is appropriate (also if the argument is value type or reference type).

wcscpy(str,_T("Some data"));
2. wcscpy does not perform boundary checking, it might be possible to have buffer overrun. If databasefilename = "abc.txt" creates a string that is just big enough to hold the data, and you subsequently use it as shown in the code above, you will get buffer overrun.

rakesh_mahajan
04-03-2006, 10:06 AM
Thanks for response.


My problem is that the value of string parameter is not passing from vb.net to vc++ dll.

When i debug dll and look for string parameter value it is shoeing "0".

If i have a function with integer parameter it works fine..

Please help me in solving this problem.


Thanks,
Rakesh