PDA

Click to See Complete Forum and Search --> : Call Delphi Assembly from VB.NET


joescho
Oct 20th, 2006, 03:38 PM
Hello Everyone:
I was hoping there was someone who has some Delphi knowledge that could help with calling a Delphi developed assembly from VB.net. The Delphi assembly is not a com object but only a dll with one exported function. It is supposed to be an AES module in which you pass a password and its encrypted equivilant and the module pases back true if they match or false if not.

I have a database with usernames/ AES encrypted passwords that were built by a Delphi program. I contacted the original programmer for the keys to decrypt these passwords, but he was unable to determine what the keys were so he built me this function.

The problem I am having is either I get false for matches or I get "Attempted to read or write protected memory. This is often an indication that other memory is corrupt."

I recieved two versions. The first one took two strings and passed back a boolean:

function checkEqual(clearString, encryptedString: string): boolean;

I found out that he made the strings short strings on the Delphi end which may be a problem on the VB.NET end.

The second assrmbly I recieved was because I could not get the first to work. It took two arrays of char and passed back a boolean.

I am currently tring the one with the arrays of char and have it defined like:

<DllImport("C:\vaebEncCheck.dll", EntryPoint:="checkEqual", SetLastError:=True, CharSet:=CharSet.Unicode, _
ExactSpelling:=True, CallingConvention:=CallingConvention.Winapi)> _
Public Shared Function checkEqual(ByVal clearString As Char(), ByVal encryptedString As Char()) As Boolean

End Function

I hope someone could help me out with this as I have tried everything I could and am clueless.

Thanks,

Joe

vyruz
Feb 26th, 2008, 09:36 AM
hi joescho
i wish i can help you but im stuck at the same problem just like you :(
do u still get the error? if not plz help me out
im using vb.net 2008 and trying to call some Delphi dll but the same error hit me all the time :|
what is the use of a DllImport statement any way??
thx

joescho
Feb 26th, 2008, 10:07 AM
I never did figure it out. I ended up going another way. The DLLImport allows you to bring in an assembly into your program, and declare the procedure or function you're trying to use so that the compiler can do the typing for the input/output parameters so you don't blow the stack when you call it.

I figure that there's not that many people who have tried to do this, so there's not an abundance of information out there for doing this.

You're either going to have to either rewrite the functionality of the Delphi assembly into your own code, or go completely Delphi for your project.

vyruz
Feb 26th, 2008, 04:43 PM
The DLLImport allows you to bring in an assembly into your program, and declare the procedure or function you're trying to use so that the compiler can do the typing for the input/output parameters so you don't blow the stack when you call it.
could u explain more what u did exactly??
maybe some code lines :D

go completely Delphi for your project.
thats what i had to do :(
and i spent 2 months learning Delphi but vb 2008 is much better! and i have no problem converting all the work into vb but i must get rid of the stupid dll thing first :(
thx again for ur response
have a nice day :thumb:

joescho
Feb 27th, 2008, 08:20 AM
I don't think I still have the code. It was a while back. If I remember correctly, I just had a DLLImport line like in my original post, then had a call in my code to execute the external procedure which is all you should have to do.

I think the problem lies in how either Delphi handles parameters, or how .NET handles parameters. If it was a problem with the declaration in the assembly, then .NET wouldn't be able to find the procedures in the DLL. Since its giving a corrupt memory error, the memory must be getting mangled either by the number of bytes on the stack, or the Delphi assembly is accessing a part of memory that .NET isn't expecting. Just my 2 cents.

vyruz
Feb 28th, 2008, 12:49 PM
i have the source code of the dll but i dont know what to change in the fn
any way thx a lot for responding :D

alchemy9
May 14th, 2009, 04:34 AM
have a look at this link

there is a download with an example


http://www.blong.com/Conferences/BorConUK2002/Interop1/Win32AndDotNetInterop.htm#PInvoke

regards

ian