Writing an ActiveX control for cs

  • Thread starter Thread starter BveB
  • Start date Start date
B

BveB

I have an dll written in c++ but I cannot use it directly in c#
because it has some complex structures that is not supported by
invocation system.

Which solution is proper writing an ActiveX component or using some
unsafe code?

In second dllimport has very poor performance(I use it for exported
function that has not have complex structure argument).Loading dll
takes long time.How can I use it c#?
 
BveB said:
I have an dll written in c++ but I cannot use it directly in c#
because it has some complex structures that is not supported by
invocation system.

Which solution is proper writing an ActiveX component or using some
unsafe code?
**** Write a managed wrapper for your C++ dll using ME C++ (visual C++ 7.x).
In second dllimport has very poor performance(I use it for exported
function that has not have complex structure argument).Loading dll
takes long time.How can I use it c#?

*** Could you be more specific?
Loading a dll is fast and only happens once (at the first function call ),
or do you mean each function call is slow?
Did you measure the call overhead? Do you have some timing figures?

Willy.
 
Hi
with the ActiveX control , you can still use the DllImport and for the
complex structure you can write the unsafe blocks and use the marshaling
class to marshal data to the unmanaged DLL.
About how to use the dll import ( although I think you should have already
done that )
Add the dll import attribute any where in your code , put the name of the
function you are to use in the entry point .
[DllImport("winmm.dll", EntryPoint="PlaySound")]
Then define the function as external
public static extern bool PlaySound_DllImport(string
pszSound,IntPtr hmod ,int fdwSound );
Define the input and output parameters of the function in your code ( in
your case it could be more than that , use whatever type into unsafe block )
bool result;
System.IntPtr resourceHandle = System.IntPtr.Zero;

Then simply call the function
result = PlaySound_DllImport("c:\\1.wav",resourceHandle,0);

hope that helps.
Mohamed Mahfouz
MEA Developer Support Center
ITworx on behalf of Microsoft EMEA GTSC
 
No I dont have any timing figures but i can see it with my eyes
program suspends a little when I call a dll function
 
Back
Top