Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Getting DLL To Work in Visual Studio

Posted on 2012-04-09
5
Medium Priority
?
708 Views
Last Modified: 2012-08-13
Through Guru.com, I had a developer create a DLL for me to include in a Visual Studio Windows Service project.  To test out his DLL, this developer included an EXE that would register the DLL on the system and he included the following code embedded in an Excel spreadsheet button's click event to call his object:

Set myObject = CreateObject("MyComponent")
    
    resultStatus = myObject.doWork()
    MsgBox resultStatus 

Open in new window


I need to have this work in Visual Studio - ideally without using Reflection - and so far I have fallen flat on my face.  Given the type of code, DLLImport is not working, I cannot directly reference the DLL as .NET does not view it as a valid COM object and registering the object does not appear to add the object to the list of available COM components.

The DLL itself is written in Python, wrapped in a C layer for portability, and I need to figure out how to make this things accessible in .NET.

Any ideas?
0
Comment
Question by:ktola
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 23

Accepted Solution

by:
wdosanjos earned 2000 total points
ID: 37824431
Here is the C# (.NET 4.0) version:
dynamic myObject = Activator.CreateInstance(Type.GetTypeFromProgID("MyComponent"));

resultStatus = myObject.doWork(); // assuming resultStatus is defined somewhere else
System.Windows.Forms.MessageBox.Show(resultStatus.ToString());

Open in new window

0
 

Author Comment

by:ktola
ID: 37824447
That is using Reflection which is dog slow and not really multithread friendly
0
 
LVL 23

Expert Comment

by:wdosanjos
ID: 37824462
I think that's your best chance to make it work with your DLL.  You could cache the MyObject instance to avoid the overhead.
0
 
LVL 20

Expert Comment

by:Daniel Van Der Werken
ID: 37824495
If it's a COM DLL, then you would be able to use regsvr32.exe to register the DLL and wrap it in an Interop for your .NET project. However, I guess it isn't, right? If it's a C/C++ DLL that isn't COM based, then you would normally use DLLImport. Otherwise, I don't think there is any other way to incorporate the code into your project.

Can you give us more information? What do you mean DLLImport isn't working?

I think Activator.CreateInstance(...) is more the way you want to go, though.

These links might prove useful, but it does use reflection:
http://www.csharp-examples.net/reflection-examples/
http://social.msdn.microsoft.com/Forums/zh/csharpgeneral/thread/fe3d7977-52f5-45d9-b142-122e1c588485
0
 

Author Closing Comment

by:ktola
ID: 37824653
Dynamic - forgot all about it - thanks!
0

Featured Post

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Flask is a microframework for Python based on Werkzeug and Jinja 2. This requires you to have a good understanding of Python 2.7. Lets install Flask! To install Flask you can use a python repository for libraries tool called pip. Download this f…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.

604 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question