473,385 Members | 1,392 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.

Using a non COM C++ DLL

Hi,
I have to use a 3rd party C++ DLL say (3PDLL)
It comes with a header file that declares its interface.
The interface is a structure say (3PStruct) that has a member for each
exposed function.
We (not I)have made a C++ dll say (MyInterface)that attaches to this DLL
and exposes its public functions.

MyInterface is then used by the main VB app.

I thought it might be possible to do the same thing in C# .

The essential MyInterface C++ code is:

HINSTANCE pDll;
Blah dllAttach;
3PStruct *pMainDllRec = NULL;

pDll = LoadLibrary("3PDLL.dll");
dllAttach = (Blah)GetProcAddress(pDll, "_dll_Attach");
if(!dllAttach(&pMainDllRec, ver_number))
{
wrong version clean up and exit
}
else
{
right version, pMainRecDll is now a pointer to 3pStruct that can be
dereferenced to any of the exposed functions.
}
So now MyInterface can now:
bool MYINTERFACE ThisFunction(bool lglResult)
{
return pMainDllRec->ThatFunction(lglResult);
}

Back to the C# world:
I have managed to Loadlibrary and GetProcAddress using IntPtrs for pDLL
and dllAttach but I come unstuck after this.

MyInterface has the advantage of the provided header file so it can
declare dllAttach to be of type Blah which is a function call that takes
pMainDllRec's address and a version string.
It seems that I am stuck with declaring dllAttach as an IntPtr.
So although I can retrieve dllAttach, I can't see how make to further
use of it to set pMainDllRec.
my C# attempt:

IntPtr p = new IntPtr(0);
IntPtr dllAttach = new IntPtr(0);
IntPtr pMainDllRec = new IntPtr(0);
p=LoadLibrary(Library);
dllAttach = GetProcAddress(p,"_dll_Attach");

So far so good..

The following is what I would like to achieve next.
I guess that this functionality if possible, would be in an unsafe
procedure .

IntPtr pMainDllRec = new IntPtr(0);
string version = "1.0.0"
if (dllAttach(&pMainDllRec, version))
{
success, we have a pointer to the functions
}
else
{
failure, wrong version message etc.
}

Is this possible in C# or should I just stick with the C++ 'MyInterface'.
Thanks
Bob
Nov 16 '05 #1
2 1494
Hi Bob,

Wrapping a function pointer into a delegate and use it in managed code is
not supported in .NET Framework v1.1, however it is a feature in Whidbey
release.

For now you need use managed C++ to do this since it supports IJW.

Thanks!

Best regards,

Ying-Shen Yu [MSFT]
Microsoft Community Support
Get Secure! - www.microsoft.com/security

This posting is provided "AS IS" with no warranties and confers no rights.
This mail should not be replied directly, please remove the word "online"
before sending mail.

Nov 16 '05 #2
Hi,
Ok, Thanks.
regards
Bob

Ying-Shen Yu[MSFT] wrote:
Hi Bob,

Wrapping a function pointer into a delegate and use it in managed code is
not supported in .NET Framework v1.1, however it is a feature in Whidbey
release.

For now you need use managed C++ to do this since it supports IJW.

Thanks!

Best regards,

Ying-Shen Yu [MSFT]
Microsoft Community Support
Get Secure! - www.microsoft.com/security

This posting is provided "AS IS" with no warranties and confers no rights.
This mail should not be replied directly, please remove the word "online"
before sending mail.

--
Please take out the garbage before using reply address.

Nov 16 '05 #3

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

Similar topics

5
by: Enos Meroka | last post by:
Hallo, I am a student doing my project in the university.. I have been trying to compile the program using HP -UX aCC compiler, however I keep on getting the following errors. ...
3
by: Mike L | last post by:
Should the command call "using" be before or after my namespace? **AFTER** namespace DataGridBrowser { using System; using System.Drawing; using System.Drawing.Drawing2D; using...
3
by: xzzy | last post by:
I was wondering why we have to have using System.Data using System.Configuration using etc.... why are they not all lumped into one 'using'? In other words, is there a best way to use...
14
by: pmud | last post by:
Hi, I need to use an Excel Sheet in ASP.NET application so that the users can enter (copy, paste ) large number of rows in this Excel Sheet. Also, Whatever the USER ENETRS needs to go to the...
8
by: acb | last post by:
Hi, I wrote a DLL Component (using Visual Studio 2005) and managed to include it into a C# Console application. I am now trying to include this component into a Web project. I copy the DLL...
0
by: Metal2You | last post by:
I'm working on an ASP.NET 2.0 application in Visual Studio 2005 that accesses a Sybase database back end. We're using Sybase SQL Anywhere 9.0.2.3228. I have installed and registered the Sybase...
10
by: mg | last post by:
I'm migrating from VB6 and have a question about using 'Using' and the best way to use it. Here is a example of a small bit of code: dbConx("open") Using CN Dim CMD As New OleDbCommand(sSQL,...
0
by: Eugene Anthony | last post by:
The problem with my coding is that despite removing the records stored in the array list, the rptPages repeater control is still visible. The rptPages repeater control displayes the navigation...
3
by: JDeats | last post by:
I have some .NET 1.1 code that utilizes this technique for encrypting and decrypting a file. http://support.microsoft.com/kb/307010 In .NET 2.0 this approach is not fully supported (a .NET 2.0...
6
by: =?Utf-8?B?U2hhd24gU2VzbmE=?= | last post by:
Greetings! I was researching AJAX to provide a solution to displaying status messages while a long process executed. I found several examples online and was able to use their code to get a quick...
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: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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
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.