Need to call C++ function from VB.NET

  • Thread starter Thread starter Marina
  • Start date Start date
M

Marina

The function is declared as :
void WINAPI AIEncrypt( LPSTR sReadable, LPSTR sEncrypted )

What is the correct way to declare the function in VB.NET, and then what is
the right way to call it? The function encrypts the first string, and stores
the encrypted version in the second parameter.
 
Hi Marina,

Probably it will be

~
Declare Ansi Sub AIEncrypt Lib "your.dll" (<MarshalAs(UnmanagedType.LPStr)>
ByVal sReadable As String, <MarshalAs(UnmanagedType.LPStr)> ByVal sEncrypted
As String)

....

Dim Result As New String(Chr(0), 256) REM you may need to change 256 to
appropriate buffer size
AIEncrypt("Some String", Result)
~

Maybe you'll have to put something like ~Alias "AIEncryptA"~ in your
declare.

I hope this helps.

Roman
 
Thanks.

So, we've been able to get this to work in a VB.NET windows app, but not in
a web application. The code is the same. We've tried making the ASP.NET user
an admin

The function just does some encryption. It's failing silently with the same
input, and the return string is empty, instead of having the encrypted
value.

Any ideas on why this would happen?
 
Back
Top