473,326 Members | 2,113 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Writing an ActiveX control for cs

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#?
Nov 16 '05 #1
5 1757

"BveB" <bb****@st.cs.deu.edu.tr> wrote in message
news:ac**************************@posting.google.c om...
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.

Nov 16 '05 #2

"BveB" <bb****@st.cs.deu.edu.tr> wrote in message
news:ac**************************@posting.google.c om...
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.

Nov 16 '05 #3
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

Nov 16 '05 #4
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

Nov 16 '05 #5
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
Nov 16 '05 #6

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

Similar topics

1
by: wang xiaoyu | last post by:
Hello: i want use activex in wxpython program,but when i use MakeActiveXClass an exception occurs. this is my source code dealing the DICOM ocx.I must note that in this program "hwtxcontrol" is...
3
by: adam | last post by:
hi is it possible to write activeX controls in C# and if so any suggestions of links to sample code would be appreciated? thanks Adam
0
by: Gazelle | last post by:
I have a dilemma, that I am hopping I can find some help with. He is the back story so everyone sort of understands what it is that I am trying to accomplish. My problem: I have multiple...
3
by: Jeffery Franzen | last post by:
Anyone know where the documentation is regarding Activex controls in asp web forms? I'm using VS.NET 2002 enterprise and am trying to use Activex controls in vb.net web form app. I do the add...
7
by: Jarod_24 | last post by:
I just downloaded a activex control that was written in C# and tried to view it on my PDA's Internet Explorer. At my regular PC it displayed just fine, but nothing showed up on the pda. Do...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.