473,396 Members | 2,147 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,396 software developers and data experts.

Please Help DLL Issue

Hi all,

Am wondering if anyone can help.

I have received a C++ none COM DLL that i must use to interact to a
peice of hardware. As I am more confident in C# I decided to create a
wrapper for the DLL. As i have found out this is not possible for MS
visual studio to do this automatically from a COM object i created a
C# DLL project to act as a wrapper for the C++ DLL.

Unfortunetly i was quite silly and created all methods in the wrapper
before testing that i could create an instance of my wrapper and the
dll would work.

Now the weird thing is lets say i have a method called init() in the C+
+ code, i have created a method like this in my c# code
public void Init()
{
//set to -1 so that we dont return succuss message by default
int x=-1;

try
{
Process p = Process.GetCurrentProcess();

IntPtr HWND = p.MainWindowHandle;
x = MyWrapper.Initialization();

if(x==0)
{
System.Console.WriteLine(x.ToString());
}
else
{
System.Console.WriteLine(x.ToString());
throw new Exception(x.ToString());
}
}
//an exception occured so return appropriate error message
catch(Exception ex)
{
System.Console.WriteLine(x.ToString());
throw new Exception(ex.Message);
}
}

Now these methods sometimes seem to work in my test application were i
create an instance of my wrapper and call the methods like this:

MYWrapper test = new MyWrapper();

test.MYInitialization()

BUT sometimes they dont seem to work, also i have noticed that if i
add the DLL imports to the top of my test application like this:

[DllImport("Vertx.dll", SetLastError = true, CharSet =
CharSet.Ansi)]
static extern int Initialization(int Port, int HWND, int HINSTANCE);

the methods seem to work more often? even though i never actually call
this method!

Am sorry if i have jumped around a bit but i think i have burnt out my
brain trying to understand what is wrong here.

Also the parameters for the init method in the C++ DLL are:

int Initialization ( int port , HWND hWnd , HINSTANCE hInst )
and i am using:

4070, HWND.ToInt32(),moduleHandle.ToInt32()

in the C# code, am not sure these are correct equivilents.

Any help would be REALLY apprecaited!

Thanks,

Adam

Jun 7 '07 #1
1 1420
Well, the first thing to figure out is, are you trying to use classes,
or functions that are exported from the dll? If you are just using
functions that are exported, then all you have to do is make the function
calls through the P/Invoke layer.

However, it seems that you need to use classes that are in the DLL. In
this case, you need to create a managed C++ project which will create a
managed assembly, but will also allow you to create the unmanaged types you
are trying to access.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"ba.hons" <ba*****@gmail.comwrote in message
news:11**********************@q66g2000hsg.googlegr oups.com...
Hi all,

Am wondering if anyone can help.

I have received a C++ none COM DLL that i must use to interact to a
peice of hardware. As I am more confident in C# I decided to create a
wrapper for the DLL. As i have found out this is not possible for MS
visual studio to do this automatically from a COM object i created a
C# DLL project to act as a wrapper for the C++ DLL.

Unfortunetly i was quite silly and created all methods in the wrapper
before testing that i could create an instance of my wrapper and the
dll would work.

Now the weird thing is lets say i have a method called init() in the C+
+ code, i have created a method like this in my c# code
public void Init()
{
//set to -1 so that we dont return succuss message by default
int x=-1;

try
{
Process p = Process.GetCurrentProcess();

IntPtr HWND = p.MainWindowHandle;
x = MyWrapper.Initialization();

if(x==0)
{
System.Console.WriteLine(x.ToString());
}
else
{
System.Console.WriteLine(x.ToString());
throw new Exception(x.ToString());
}
}
//an exception occured so return appropriate error message
catch(Exception ex)
{
System.Console.WriteLine(x.ToString());
throw new Exception(ex.Message);
}
}

Now these methods sometimes seem to work in my test application were i
create an instance of my wrapper and call the methods like this:

MYWrapper test = new MyWrapper();

test.MYInitialization()

BUT sometimes they dont seem to work, also i have noticed that if i
add the DLL imports to the top of my test application like this:

[DllImport("Vertx.dll", SetLastError = true, CharSet =
CharSet.Ansi)]
static extern int Initialization(int Port, int HWND, int HINSTANCE);

the methods seem to work more often? even though i never actually call
this method!

Am sorry if i have jumped around a bit but i think i have burnt out my
brain trying to understand what is wrong here.

Also the parameters for the init method in the C++ DLL are:

int Initialization ( int port , HWND hWnd , HINSTANCE hInst )
and i am using:

4070, HWND.ToInt32(),moduleHandle.ToInt32()

in the C# code, am not sure these are correct equivilents.

Any help would be REALLY apprecaited!

Thanks,

Adam

Jun 7 '07 #2

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

Similar topics

22
by: owen | last post by:
I have been developing web-based applications for around 3 years, first using ASP, and more recently, ASP.NET. I am starting to wonder if web applications are really the way forward for...
3
by: Jane Withnolastname | last post by:
I sent the following message to my ISP, which provides free webspace: I am using server-side includes on my webspace, but your server does not recognize index.shtml as the main page. Since your...
1
by: Mat | last post by:
"Variable AAA is not declared" but the variable is there. where i cut and paste the code( variable declaration), the error disappear Please HELP
55
by: Sam | last post by:
Hi, I have a serious issue using multithreading. A sample application showing my issue can be downloaded here: http://graphicsxp.free.fr/WindowsApplication11.zip The problem is that I need to...
1
by: David Van D | last post by:
Hi there, A few weeks until I begin my journey towards a degree in Computer Science at Canterbury University in New Zealand, Anyway the course tutors are going to be teaching us JAVA wth bluej...
8
by: John Austin | last post by:
I need to understand why if I add a control and use AddHandler to connect its click event, it will work in Page_Load, but not in a Button_Click. The idea is that the user types some data, presses...
7
by: rn5a | last post by:
This is the second time I am asking this question in this newsgroup since I haven't got a solution or response from anyone in my previous post & I need to resolve this issue desperately. Sorry for...
4
by: Brad Isaacs | last post by:
I am working with ASP.NET 2.0 and using an SQL Server 2000 database. I am using Visual Studio 2005 and developing on my Local machine. I am working with Login controls ASP.Configuration, I...
1
by: =?Utf-8?B?YXZucmFv?= | last post by:
We have a web service that gets data in xml format. In that Xml data, we parse few date fields that are in this format <data datefield="12/26/2008" timefield="16:33:45" ...> we parse it into a...
5
by: simon | last post by:
hello, I have a server set up on my local (home) network and can not get an ajax application to run on the box. it works fine on our developement server and also works fine locally. I...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.