473,385 Members | 1,875 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,385 software developers and data experts.

DllImport and error handling

I am calling a c++ dll using DllImport and is loading a number of functions.

I all work fine but I need the code to be able to react to a case where the
dll is missing or some of the functions are missing.
My C++ code looks like this:
if(!Dll_)
Dll_ = LoadLibrary(dllname_.c_str());
if(Dll_)
{
SetMixture_ = (tdSetMixture_*)GetProcAddress(Dll_, "SetMixture");
if(!SetMixture_)
///and so on

How to I write the same code in C#?

Thanks Torben
May 26 '06 #1
1 2579
Hello, Torben!

TL> I all work fine but I need the code to be able to react to a case where
TL> the dll is missing or some of the functions are missing.
TL> My C++ code looks like this:
TL> if(!Dll_)
TL> Dll_ = LoadLibrary(dllname_.c_str());
TL> if(Dll_)
TL> {
TL> SetMixture_ = (tdSetMixture_*)GetProcAddress(Dll_, "SetMixture");
TL> if(!SetMixture_)
TL> ///and so on

TL> How to I write the same code in C#?

You will have to P/Invoke ( again DllImport ) on LoadLibrary and GetProcAddress functions to test if specified
function exists in the loaded module...
--
Regards, Vadym Stetsyak
www: http://vadmyst.blogspot.com
May 26 '06 #2

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

Similar topics

13
by: Thelma Lubkin | last post by:
I use code extensively; I probably overuse it. But I've been using error trapping very sparingly, and now I've been trapped by that. A form that works for me on the system I'm using, apparently...
15
by: Jim | last post by:
I am extremely frustrated. I am building c# application for a call center and am using a third party API to access some hardware. When develop and test my class using the windows console the...
2
by: k | last post by:
Hiya, I'm hoping somebody can help me out here, I have searched for this problem but had no joy in finding a solution. I'm trying to use the DllImport attribute as follows: I have...
2
by: Brian Anderson | last post by:
Hello, is it possible to use DllImport to call a DLL in ASP.NET ? Or is it necessarry that my DLL has to be copied into \System32 ? My DLL is a native C++ 7.1 DLL (not managed, no COM, no...
2
by: Juan Martinez | last post by:
In a form i have a drawing control called VectorDraw and a textbox. The text box is disable, when i am using the drawing area i can write some text, what i want to do is that when i press any key...
1
by: sharmadeep1980 | last post by:
Hi All, I am facing a very unique problem while compling my project in "Release" build. The project is building in DEBUG mode but giving linking error on Release build. Here is the error:...
2
by: nospam | last post by:
Hello - I am getting a compile error "Expected class, delegate, enum". I am trying to create a Class Library in C# which wraps around an unmanaged DLL that manages a MIDI interface. In my...
6
by: vivekanandaprasanth | last post by:
hi, I have exported a class which i have written in win32 static lib app. Now i have written a wrapper class for the same. But when i am trying to compile it is giving me some linker errors....
9
by: jjones7947 | last post by:
Am doing a JNI wrap on a C++ API, am using VC7 and Eclipse. In preparation, I created a C++ executable which mimicked the flow of the JNI, i.e. a driver file which called methods in file with methods...
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...
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
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.