in C#, calling third party API (C++) - c#

Was wondering if anyone would be so kind to point me in the right direction on how to call a third party's C++ DLL in C#. The API is closed source but the header files are available.
I've read up on using P/Invoke but after further diving, it's leading to marshalling very complex data structures across, and that's IF I can do the declarations for the third party classes/functions.
If there's any reading material / tutorials out there you can recommend or just point me in the right direction, I would appreciate it.
Thanks so much in advance

I found http://www.pinvoke.net/ to be very helpful.
Also the http://clrinterop.codeplex.com/releases/view/14120
Additionally, what I did that I found helpful was to do a test solution. Start off with making a C# console app that initially does nothing, then make another Project (File, New, Project, Visual C++, Win32 Console Application)
When the Wizard appears, choose DLL, Export symbols, (ATL and/or MFC if you need that).
When the Project appears, compile it as is and copy the DLL to you output folder of you C# Project
Use the P/Invoke Interop Assistant to generate the C# method based on the header (I'd start with the function that takes no params and returns an int.)
then call that from your C# console app.
Once I'd established how it worked with something really simple it was much easier to expand a bit at a time.
Try writing the C# calls yourself and then use the P/Invoke Interop Assistant to double check. Best wishes.

Related

control a wpf from matlab by using a c# dll

i would like to know weather it is possible to control some wpf application written in c# by using a c# dll out of matlab.
what i need is the possibility to start the MainWindow and i have to be able
to get some values into my controller.
What i found so far was things working from c# that use matlab, but the other way round seems not to be that much populatet, as i found nothing i could really use.
I allready tried to import a .net Library, but i dont seem to be able to open a external class from my dll.
So if you could help me on this it would be great.
Regards,
justSomeone
Ok, i did just find out, that i can also import my .exe file into Matlab instead of only dlls .
I am using the function NET.addAssebly('Path.exe') to do this.
Path.exe is just a symbol that it is directed to the place of the .exe file.
I achieved to be able to use my methods as i wanted i do have my instance of the class. So i am happy now. :D
But if you have other solutions which are more handy, dont hesitate to post them. There might still be interesting things to discover :)
Regards,
justSomeone

How can I use GMap.NET dll in delphi?

I'm a C# programmer who use GMap.NET for C# for a long time!
Now I want to know if I can use its dll files in Delphi.
I've tried to import its dll files in a VCL Forms Application in Delphi EX3 and add GMapControl to a form. But I don't know how to use it now! For example GMapControl has lots of properties in C#. like Position, Zoom, etc. But now I can't see these properties in GMapControl that is imported into Delphi.
I'm looking for a way to use it in Delphi and if it's not possible, I would be glad to know this fact in order not to waste time on it anymore!
thanks in advance for any help.

Running C++ Qt app from C#

Introduction: I have qt-opencv-multithreaded - Qt/OpenCv application writen in C++ (running on Windows). But I also have another application written in C#.
C++ app does analysis of video and identifies robots (position, rotation). And stores it in variable inside ProcessingThread.
C# app receives these values and decides where should robots move.
I decided to use C# project as startup project. And I tried to create C++/cli wrapper for qt-opencv-multithreaded .
Questions: Now I have two questions:
How do I run the Qt app from another project? I tried to add include MainWindow.h to wrapper project and create instance from it. I added also directory of qt-opencv-multithreaded to "Additional Include Directories" but it wants also qt directories and I am worried that it is not a right way to do it. So how should I do it?
I know I need to use wrapper. But how do I sent data stored in list of robots in C++ project in processing thread to C# project? (where robot includes cv::Point2i position and cv::Point2i rotation and some other not important inner class) I tried to "pseudoserialize" values into string, send it to C#, and then "deserialize" it to prepared object. But it seems somehow wrong. Is there simple way to do what I need?
Thank you
If you want to run it as a stand-alone process, C# provides facilities for doing so.
If you want to call individual functions of your C++ code from C#, look into P/Invoke

Reading a File While Being Written to by Another Program(Windows)

So basically, I'm trying to read a log file from a game while that game is running in order to have my program react to it in dynamic ways. I know it's possible, as other programs such as Notepad(++) are able to do it. However, after searching for an answer, most of what I can come up with is only Linux related.
I have no idea as to how to go about this, help in doing so with either C++ or C# would be great. Even though I would prefer native C++ over C#.
The "native" winapi solution is CreateFile, and in particular its dwShareMode parameter.

Convert VBA in access to C#

I have acces file with forms that create excel file with multiple spreadsheets and I have a task that converts it to C# application that do the same thing the VBA code do and it has alot of code
Can I convert the VBA code to (e.g .dll file) that enable me to use the VBA methods in C# or anyway to use VBA code in C# instead of convert it ?
Thanks,
Mohammed Thabet Zaky
http://thabettech.blogspot.com/
If you want to do it yourself, it is possible to just reference the COM stuff. I did this with another application that utilized VBA (AutoCAD). What we ended up doing was creating a .net class that referenced the COM interop and then copied all of the code into that project. This is how we created the .dll file. Then we slowly refactored the vba code into C#.
The copy and paste isn't completely seemless. You do need to make some adjustments. For example thisworkbook, activesheet, and all of those items that are referenced automatically don't work automatically (because you are not out of Excel's process). But (at least for us) it was better than completely re-creating the logic.
Here is a link to some reference material - http://au.autodesk.com/?nd=e_class&session_id=5084. It references Autocad, but doing it in Excel would be very similar.
Hope this helps.
You may have success with the VB Migration Partner, even though it was designed for Visual Basic applications, not office. At least in terms of syntactic migration from VBA to C# it could help.

Categories