Click here to Skip to main content
15,917,642 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hi

I am trying to import a C++ dll(writen by some hardware manufacturer) into another C# dll that I am designing.

As i am new to this Dll imports and Visual studio (c#, c++) I am having a hard time to do that.

I tried to add as reference, I placed the dll in to physical location(bin), I tried to Register the dll with cmd line, all these failed
Later I tried to use reflections by creating Delagates for the methods.

it did not work,

so now tried to do the MArshalAs for the variables (Handler) that are in the c++ dll functions.

Can some body please provuid source code for how to Import a c++ dll into another c# dll.

I have looked at general examples....but still no luck....

Thanks in advance...
Posted
Updated 4-May-11 16:17pm
v2
Comments
Sergey Alexandrovich Kryukov 4-May-11 20:50pm    
This is too general question. To answer it, don't search for the sample close to yours, you may never find it. Just read all on the topic, or show the code you want to P/Invoke.
--SA
Sergey Alexandrovich Kryukov 4-May-11 21:01pm    
Please see my answer,
--SA

Please look how to use unmanaged codes in .NET environment.Unmanaged codes[^] .
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 4-May-11 20:48pm    
Sorry, Wonde; there is not a sample with MarshalAs here. OP needs some closer sample or overview showing all techniques or just say "Search harder".
--SA
As I say, this is too general question; so nobody can provide a "sample". A sample for what, exactly?

Try to learn it all:
http://en.wikipedia.org/wiki/PInvoke[^],

Start from here:
http://msdn.microsoft.com/en-us/library/sd10k43k.aspx[^],
http://msdn.microsoft.com/en-us/library/system.runtime.interopservices.dllimportattribute.aspx[^]
http://msdn.microsoft.com/en-us/library/system.runtime.interopservices.marshalasattribute(v=VS.100).aspx[^].

After all, provide a signature of the function you want to P/Invoke and what you try to do, just few lines of code. Use "Improve question".

—SA
 
Share this answer
 
A good inspiration could be pinvoke.net[^]
 
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