Importing C++ DLL in C# .NET

A

abdul

I have imported C++ dll in C#. But i am getting this error.
"An unhandled exception of type 'System.EntryPointNotFoundException' occurred in ConsoleApplication.exe
Additional information: Unable to find an entry point named getInitializedCount in DLL Common.dll. "
Code which i have written

using System;
using System.Runtime.InteropServices;
namespace ConsoleApplication3
{
class Class1
{
[DllImport("Common.dll",CharSet = CharSet.Auto,EntryPoint = "getInitializedCount")]
static void Main(string[] args)
{long s = 0;
s = getInitializedCount();
Console.WriteLine(s);
}
}
}
Also i had tried with DUMBIN \exprot.. that also not working..

I request you please suggest me the write solution.. Thanks in ADvance.

From http://www.developmentnow.com/g/36_2003_9_0_16_0/dotnet-languages-csharp.ht

Posted via DevelopmentNow.com Group
http://www.developmentnow.com
 
R

Rich

abdul said:
I have imported C++ dll in C#. But i am getting this error.
"An unhandled exception of type 'System.EntryPointNotFoundException' occurred in ConsoleApplication.exe
Additional information: Unable to find an entry point named getInitializedCount in DLL Common.dll. "
Code which i have written

using System;
using System.Runtime.InteropServices;
namespace ConsoleApplication3
{
class Class1
{
[DllImport("Common.dll",CharSet = CharSet.Auto,EntryPoint = "getInitializedCount")]
static void Main(string[] args)
{long s = 0;
s = getInitializedCount();
Console.WriteLine(s);
}
}
}
Also i had tried with DUMBIN \exprot.. that also not working..

I request you please suggest me the write solution.. Thanks in ADvance..

From http://www.developmentnow.com/g/36_2003_9_0_16_0/dotnet-languages-csharp.htm

Posted via DevelopmentNow.com Groups
http://www.developmentnow.com

Abdul,

I had done a similar import in C++ (using unmanaged DLL in managed CLI
code) and the import call looked like this:

[DllImport("Test_DLL", EntryPoint="Function")]
extern "C" void Function( void );

Note that this has a function prototype following the "[DllImport ...]"
statement. I haven't tried this in C#, but could it be that you need a
similar prototype so the program knows what the function call should
look like?

You may want to test your DLL from C++ to verify that you can make this
work there. If that works then it is just a matter of doing the same
thing in C# syntax.

Rich
 
A

Abdul

This the sample code..Sorry,by mistake i missed this line "public static extern long getInitializedCount();"




using System;
using System.Runtime.InteropServices;
namespace ConsoleApplication3
{
class Class1
{
[DllImport("Common.dll",EntryPoint = "getInitializedCount")]

public static extern long getInitializedCount();


static void Main(string[] args)
{long s = 0;
s = getInitializedCount();
Console.WriteLine(s);
}
}
}


The code is compiling .. During runtime i am getting the execption. what i had mentioned..

More over The common.dll is Third party DLL.


From http://www.developmentnow.com/groups/viewthread.aspx?newsgroupid=36&threadid=85543

Posted via DevelopmentNow.com Group
http://www.developmentnow.com
 
W

Willy Denoyette [MVP]

Abdul said:
This the sample code..Sorry,by mistake i missed this line "public static extern long
getInitializedCount();"




using System;
using System.Runtime.InteropServices;
namespace ConsoleApplication3
{
class Class1
{
[DllImport("Common.dll",EntryPoint = "getInitializedCount")]

public static extern long getInitializedCount();


static void Main(string[] args)
{long s = 0;
s = getInitializedCount();
Console.WriteLine(s);
}
}
}


The code is compiling .. During runtime i am getting the execption. what i had mentioned..

More over The common.dll is Third party DLL.



From http://www.developmentnow.com/groups/viewthread.aspx?newsgroupid=36&threadid=855431

Posted via DevelopmentNow.com Groups
http://www.developmentnow.com



If "getInitializedCount" (beware the casing) is not exported by the third party dll, you
won't be able to call it.
Also note that a long in C# in a 64bit integer, I'm sure the API doesn't return a 64bit
integer but a 32bit value.

Willy.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top