TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Jesper Axelsen
NA
1
2.1k
Calling function in unmanaged library from c# returns an error
Jan 13 2012 4:15 PM
Hi
I hope someone will be able to help me solve this issue.
The following two functions are given from a DLL documentation. The DLL is an unmanaged library. The CCC_EventHandlerFunc is an eventhandler wich is registered using the CCC_RegisterEventHandler function.
long CCC_RegisterEventHandler( CCC_EventHandler handler, BYTE evmask, LONG param );
void CCC_EventHandlerFunc(WORD event_id, LPVOID data, LONG param);
My problem is, that when I call CCC_RegisterEventHandler the function doesn't return 0, which it should to indicate no errors.
Here is what I have so far (in c#):
1. Declared a delegate that matches the CCC_EventHandlerFunc
[UnmanagedFunctionPointer(CallingConvention.Cdecl)] <--- tried both with an without this line
public delegate void CCC_EventHandlerFunc(
UInt16 event_id,
IntPtr data,
Int32 param
);
2. Used DllImport to access CCC_RegisterEventHandler in the unmanaged library.
[DllImport("ccc.dll")]
public static extern Int32 CCC_RegisterEventHandler(
[MarshalAs(UnmanagedType.FunctionPtr)] CCC_EventHandlerFunc handler,
byte evmask,
Int32 param
);
3. Made an instance of the delegate
private static CCC_EventHandlerFunc m_CCC_EventHandlerFunc = new CCC_EventHandlerFunc(Fnc_CCC_EventHandlerFunc);
4. When calling the sequence:
if (CCC_ProtocolSelect("pro:arq;cha:tcp;192.168.10.150:0") != 0)
return;
int version = CCC_ProtocolStartV(-1, -1);
Int32 res = CCC_RegisterEventHandler(m_CCC_EventHandlerFunc, 0, 0);
if (res != 0)
return;
res ends up being nonzero which indicates that an error has occured.
Any suggestions are appreciated.
/Jesper
Reply
Answers (
1
)
C# Problems during saving data on a Excel File shared in LAN
Here goes my GUI