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

Call C function from C# problem EntryPointNotFoundException

Hello,

I'v a dll written in C/C++. I only have the header file.
I dont know how to declare the external funtion:
I've got a EntryPointNotFoundException, I think because of the wrong
return type.
The function in the header file return a enum. But I don't know how to
declare it in my c# file.
Can anybody help me?

[DllImport("IHUAPI.dll")]
public static extern int ihuConnect(String server,String
username,String password,ref long serverhandle);

This is the header file:
#define IHUAPI __stdcall

/*
** All possible errors returned by the API functions.
** These do not need to match system API
*/
typedef enum {
ihuSTATUS_OK = 0,
ihuSTATUS_FAILED = 100,
ihuSTATUS_API_TIMEOUT = 101,
ihuSTATUS_NOT_CONNECTED = 102,
ihuSTATUS_INTERFACE_NOT_FOUND = 103,
ihuSTATUS_NOT_SUPPORTED = 104,
ihuSTATUS_DUPLICATE_DATA = 105,
ihuSTATUS_NOT_VALID_USER = 106,
ihuSTATUS_ACCESS_DENIED = 107,
ihuSTATUS_WRITE_IN_FUTURE = 108,
ihuSTATUS_WRITE_ARCH_OFFLINE = 109,
ihuSTATUS_ARCH_READONLY = 110,
ihuSTATUS_WRITE_OUTSIDE_ACTIVE = 111,
ihuSTATUS_WRITE_NO_ARCH_AVAIL = 112,
ihuSTATUS_INVALID_TAGNAME = 113,
ihuSTATUS_LIC_TOO_MANY_TAGS = 114,
ihuSTATUS_LIC_TOO_MANY_USERS = 115,
ihuSTATUS_LIC_INVALID_LIC_DLL = 116,
ihuSTATUS_NO_VALUE = 117,
ihuSTATUS_NOT_LICENSED = 118,
ihuSTATUS_CALC_CIRC_REFERENCE = 119,
ihuSTATUS_DUPLICATE_INTERFACE = 120,
ihuSTATUS_BACKUP_EXCEEDED_SPACE = 121,
ihuSTATUS_INVALID_SERVER_VERSION = 122,
ihuSTATUS_DATA_RETRIEVAL_COUNT_EXCEEDED = 123,
ihuSTATUS_INVALID_PARAMETER = 124,
ihuSTATUS_MAX_ERROR_NUM = 124

} ihuErrorCode;
/* for connecting to one server */
ihuErrorCode IHUAPI ihuConnect
(
char * server,
char * username,
char * password,
long * serverhandle
);
Jun 27 '08 #1
4 2837
pe******@gmail.com wrote:
Hello,

I'v a dll written in C/C++. I only have the header file.
I dont know how to declare the external funtion:
I've got a EntryPointNotFoundException, I think because of the wrong
return type.
The function in the header file return a enum. But I don't know how to
declare it in my c# file.
Can anybody help me?

[DllImport("IHUAPI.dll")]
public static extern int ihuConnect(String server,String
username,String password,ref long serverhandle);
Well, first up, you forgot to specify the CallingConvention. It's pretty
clear from your header file you want CallingConvention.StdCall
>
This is the header file:
#define IHUAPI __stdcall

/*
** All possible errors returned by the API functions.
** These do not need to match system API
*/
typedef enum {
ihuSTATUS_OK = 0,
ihuSTATUS_FAILED = 100,
ihuSTATUS_API_TIMEOUT = 101,
ihuSTATUS_NOT_CONNECTED = 102,
ihuSTATUS_INTERFACE_NOT_FOUND = 103,
ihuSTATUS_NOT_SUPPORTED = 104,
ihuSTATUS_DUPLICATE_DATA = 105,
ihuSTATUS_NOT_VALID_USER = 106,
ihuSTATUS_ACCESS_DENIED = 107,
ihuSTATUS_WRITE_IN_FUTURE = 108,
ihuSTATUS_WRITE_ARCH_OFFLINE = 109,
ihuSTATUS_ARCH_READONLY = 110,
ihuSTATUS_WRITE_OUTSIDE_ACTIVE = 111,
ihuSTATUS_WRITE_NO_ARCH_AVAIL = 112,
ihuSTATUS_INVALID_TAGNAME = 113,
ihuSTATUS_LIC_TOO_MANY_TAGS = 114,
ihuSTATUS_LIC_TOO_MANY_USERS = 115,
ihuSTATUS_LIC_INVALID_LIC_DLL = 116,
ihuSTATUS_NO_VALUE = 117,
ihuSTATUS_NOT_LICENSED = 118,
ihuSTATUS_CALC_CIRC_REFERENCE = 119,
ihuSTATUS_DUPLICATE_INTERFACE = 120,
ihuSTATUS_BACKUP_EXCEEDED_SPACE = 121,
ihuSTATUS_INVALID_SERVER_VERSION = 122,
ihuSTATUS_DATA_RETRIEVAL_COUNT_EXCEEDED = 123,
ihuSTATUS_INVALID_PARAMETER = 124,
ihuSTATUS_MAX_ERROR_NUM = 124

} ihuErrorCode;
/* for connecting to one server */
ihuErrorCode IHUAPI ihuConnect
(
char * server,
char * username,
char * password,
long * serverhandle
);

Jun 27 '08 #2
I tryed this:

[DllImport("IHUAPI.dll", CallingConvention =
CallingConvention.StdCall)]
public static extern ihuErrorCode ihuConnect(string server,
string username, string password, ref long serverhandle);

[DllImport("IHUAPI.dll", CallingConvention =
CallingConvention.StdCall)]
public static extern ihuErrorCode ihuDisconnect(ref long
serverhandle);

public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
long handle = 0;

//ihuConnect("dataserver", "", "", ref handle);
ihuDisconnect(ref handle);
//this.textBox1.Text = error.ToString();
}
But still gives me a EntryPointNotFoundException
Jun 27 '08 #3
Hi there,

Try an IntPtr instead of an int and use the Marshal.PtrToStructure
method.
Note that you will have to describe the enum with the [StructLayout]
attribute.
Since you have ints in the original struct I don't think this is going
to be a problem.

Here's an article about it:

http://msdn.microsoft.com/en-us/library/4ca6d5z7.aspx

And this is a very good book, it can help you with lots of interop
scenarios:

http://www.amazon.com/NET-2-0-Intero.../dp/1590596692
Jun 27 '08 #4
pe******@gmail.com wrote:
I tryed this:

[DllImport("IHUAPI.dll", CallingConvention =
CallingConvention.StdCall)]
public static extern ihuErrorCode ihuConnect(string server,
string username, string password, ref long serverhandle);

[DllImport("IHUAPI.dll", CallingConvention =
CallingConvention.StdCall)]
public static extern ihuErrorCode ihuDisconnect(ref long
serverhandle);

public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
long handle = 0;

//ihuConnect("dataserver", "", "", ref handle);
ihuDisconnect(ref handle);
//this.textBox1.Text = error.ToString();
}
But still gives me a EntryPointNotFoundException
Is the DLL export C++ name mangled? That will cause some grief.

Use Dependency Walker (comes with the Windows SDK, updates at
www.dependencywalker.com) to view the export table of the DLL and post the
exact name of the export here.

Also, C++ long is 32 bits, so change your serverhandle parameter to ref
Int32 instead of ref long.
Jun 27 '08 #5

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

Similar topics

3
by: JoeK | last post by:
Hey all, I am automating a web page from Visual Foxpro. I can control all the textboxes, radio buttons, and command buttons using syntax such as: ...
0
by: BetaTesterWannabe | last post by:
I have an unmanaged win32 dll, fileparser.dll I have a managed c++ dll, fileparser_mcpp.dll, that references fileparser.dll. I then reference fileparser_mcpp.dll from some c# code. in...
13
by: Bern McCarty | last post by:
I have run an experiment to try to learn some things about floating point performance in managed C++. I am using Visual Studio 2003. I was hoping to get a feel for whether or not it would make...
12
by: glutz7878 | last post by:
I have no trouble passing __delegate ptrs to native C functions in DLLs, however when attempting to pass the __delegate ptr to a native C++ function in a DLL I get the following runtime exception:...
5
by: Kurt Van Campenhout | last post by:
Hi, I am trying to get/set Terminal server information in the active directory on a windows 2000 domain. Since the ADSI calls for TS don't work until W2K3, I need to do it myself. I'm fairly...
11
by: yangsuli | last post by:
i want to creat a link when somebody click the link the php script calls a function,then display itself :) i have tried <a href=<? funtion(); echo=$_server ?>text</a> but it will call the...
9
by: CryptiqueGuy | last post by:
Consider the variadic function with the following prototype: int foo(int num,...); Here 'num' specifies the number of arguments, and assume that all the arguments that should be passed to this...
6
by: RandomElle | last post by:
Hi there I'm hoping someone can help me out with the use of the Eval function. I am using Access2003 under WinXP Pro. I can successfully use the Eval function and get it to call any function with...
6
by: Jeffrey Walton | last post by:
Hi All, Sorry about dropping thish on M.P.D.L.CSharp. There is no M.P.D.L.VC. So I hope someone has come across the issue... How does one export a function (not a class) in a managed Dll? ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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?
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...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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.