Click here to Skip to main content
15,881,248 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi all,
I am calling a function in Delphi dll from C#.I am getting an exception saying
"System.Runtime.InteropServices.SEHException occurred in transliteration.exe.
Additional information:External componenet has thrown an exception".

Function signature in dll is like this:
FUNCTION foo(PASS1,PASS2 : LongInt; Astring, BString : PChar; Scrpt : LongInt) : LongInt; stdcall;EXPORT;

& corresponding signature in C# is -
public static extern int foo(Int32 pass1, Int32 pass2, string txtToConvert, StringBuilder convText, ref Int32 scriptCode);

The function is called on textbox leave event.I need to pass last parameter in C# by reference.If i don't I get an access violation exception.I surfed the internet about this exception & got to know that this is related to Application.EnableVisualStyles(); function in Program.cs (I am not sure about this.)Is it true or is there is any other solution for this?

The same function is working on my side but on client's machine its giving an exception.Machine configuration is exactly same.

Please help me.
Thanks.
Posted
Updated 27-Apr-11 18:37pm
v3
Comments
JF2015 28-Apr-11 0:36am    
Improved formatting.

The C# function is not corresponding to the Delphi one. How can it be StringBuilder, ever? Last parameter is not by ref but by value.

Try
C#
public static extern Int32 foo(
    Int32 pass1, Int32 pass2,
    string txtToConvert, string convText,
    Int32 scriptCode);


I'm not really sure about one of the parameters of the type PChar. If one of the parameters is meant to be output, probably both signatures are incorrect.

If last parameter should be by reference, it could be var or const in Delphi (yes, Delphi has a weird feature: const before a parameter means "constant reference", not just constant), and in C# in should be out or ref (it only depends on function implementation semantic and affects the usage by the caller).

—SA
 
Share this answer
 
v3
Comments
bsaurabh 28-Apr-11 0:56am    
Thanks for the quick reply SAKryukov.
I have tried with the string instead stringBuilder but it gives me the accessViolation exception & same is the case with the last parameter also.
bsaurabh 28-Apr-11 1:04am    
I am totally agree with you.Even I have tried the same but it doesnt work.
Will you please tell me the root cause for this exception to occur?
I am totally confused now.
bsaurabh 28-Apr-11 1:12am    
When I tried with the string instead stringbuilder it returns a blank string but stringbuilder give proper output.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900