473,465 Members | 1,922 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Calling Delphi code from C#

Hi,

I have a delphi dll which I am trying to call from C# but something
isn't working, I get an SEHException thrown by the dll but I don't get
enough info to debug it. I can't change the dll either.

Could someone please take a look and see if or what I'm doing wrong?

Many thanks,

John Walsh

class ConversionNative
{
public delegate bool ConversionEventHandler(int currentFrame,
int totalFrames);
public event ConversionEventHandler ConversionStatus;

[DllImport("swf2avi.dll", EntryPoint="CreateAVI",
CallingConvention = CallingConvention.StdCall)]
public static extern void CreateAVI(ref TVideoParams
videoParams);

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi,
Pack = 1)]
public class TVideoParams {

public int mailForm_handle;
[MarshalAs(UnmanagedType.ByValTStr , SizeConst=150)] public
string swf_name;
[MarshalAs(UnmanagedType.ByValTStr , SizeConst=150)] public
string avi_name;
public int avi_bitrate;
public byte avi_fps;
public byte avi_gop;
[MarshalAs(UnmanagedType.FunctionPtr)]public
ConversionEventHandler callback_fn;
}

public void convert()
{
ConversionStatus = updateStatus;

TVideoParams vParams = new TVideoParams();
vParams.avi_bitrate = 22000;
vParams.avi_fps = 3;
vParams.avi_gop = 12;
vParams.avi_name = @"C:\test\Slide4.avi";
vParams.swf_name = @"C:\test\Slide4.swf";
//vParams.mailForm_handle = 0;// new IntPtr(1);
vParams.callback_fn = ConversionStatus;

CreateAVI(ref vParams);

}

private bool updateStatus(int currentFrame, int totalFrames){
Console.WriteLine ("Processed " + currentFrame + " out of "
+ totalFrames + " frames...");

return true;
}
}

Jun 2 '06 #1
2 2629
je*******@gmail.com wrote in
news:11*********************@g10g2000cwb.googlegro ups.com:
Hi,

I have a delphi dll which I am trying to call from C# but
something isn't working, I get an SEHException thrown by the dll
but I don't get enough info to debug it. I can't change the dll
either.

Could someone please take a look and see if or what I'm doing
wrong?


John,

32-bit Delphi code has no idea how to work with a .Net class
(TVideoParams).

One possible solution that comes to mind is to create a proxy DLL w/
Delphi. The proxy would expose a routine that took as parameters the
individual fields that make up the TVideoParams class. The proxy
would then package these values up in the Delphi version of
TVideoParams and pass that to CreateAVI in swf2avi.dll.

--
Hope this helps.

Chris.
-------------
C.R. Timmons Consulting, Inc.
http://www.crtimmonsinc.com/
Jun 3 '06 #2
je*******@gmail.com wrote:
Hi,

I have a delphi dll which I am trying to call from C# but something
isn't working, I get an SEHException thrown by the dll but I don't get
enough info to debug it. I can't change the dll either.

Could someone please take a look and see if or what I'm doing wrong?


Hi,
you haven't posted the Pascal implementation of the structure
TVideoParams, at least regarding the C# implementation seems
to be correct. But it's hard to tell, because of the missing
Pascal definitions.

If you have a Delphi compiler I would do the following:

a) Create a new dll with the same function exported and single
step through the code, if the function is called correctly
and where it does crash.

b) Use Delphi.NET and compile a wrapper DLL for the native one.
If the function is called without crashing you can use an
IL debugger to get the structure definition and you should
be able to compare this one with your own.
Hope that helps.
Andre
Jun 4 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Erva | last post by:
Hi, Is there someone who has moved from Delphi to VS.NET? I'am using Delphi currently but seriously considering to moving VS.NET. I would like to hear if someone has already done that, is it...
1
by: ARTMIC | last post by:
Hello, could someone please help me out, i'm trying to call a Delphi 6.0 custom DLL from inside of a C# windows project. what am i doing wrong? i use the following declaration: public class...
1
by: ARTMIC | last post by:
Hello, could someone please help me out, i'm trying to call a Delphi 6.0 custom DLL from inside of a C# windows project. i use the following declaration: static extern double...
3
by: lukeharpin | last post by:
Currently I have been developing applications in Delphi 7. Recently I meet up with a friend of mine who previously developed in Delphi, from version 1 - 7. When Delphi 8 .net was release he found...
4
by: Three | last post by:
Hi there, I have to integrate a .Net application into a Delphi application somehow. The simplest method is to get the Delphi app to call a .Net console app, however it would be better for...
2
by: Prabhat | last post by:
Hello ALL, I have ASP pages that calls some ISAPI dll that created using Delphi for generating reports. The report page opens fine for 1st time when invoked but next time i get error like "Name...
5
by: kelvin.koogan | last post by:
How can I call a function in a Delphi DLL from C++/CLI? The Delphi function is declared as follows: function Func1(IsDsb: Boolean; FirstStr, SecondStr : String): String; I've tried ...
11
by: gnuist006 | last post by:
Is there a Delphi equivalent in the C world or Scheme/LISP world ? Recently, Delphi is in resurgence. In Russia people are using like crazy. For example, Bolega has written a free image...
0
by: BornTOCode | last post by:
Hello, I am attempting to call a (Delphi) win32 DLL from a Delphi.Net webservice. I am using a slightly modified version of the hello world webservice that comes with Delphi 2006. The DLL...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.