Hi All,
I have a serious problem here which is bugging me for past few days.
I have a native DLL(Win32), and it exposes only on function called
GetFunctionList
Now this function takes a pointer to pointer of a Structure as an argument.
The Structure is something like
struct func_pointer_li st{
void (*fnA)(int a,int b);
int (*fnB)(float a, double b);
}
Now I have to write an Wrapper for this Native DLL in C#.
What I did was I wrote an Structure in C# containing some delegates like this....
[UnmanagedFuncti onPointer(Calli ngConvention.Wi napi)]
public delegate void pfnA(int a, int b)
[UnmanagedFuncti onPointer(Calli ngConvention.Wi napi)]
public delegate int pfnA(float a, double b)
[StructLayout(La youtKind.Sequen tial, CharSet = CharSet.Ansi)]
public struct func_pointer_li st
{
public pfnA fnA;
public pfnB fnB;
}
Now I call this Function called GetFunctionList something like this:
using FUNCTION_LIST_P TR_PTR = System.IntPtr;
[DllImport("NATI VE.DLL", CharSet = CharSet.Ansi)]
public extern static void C_GetFunctionLi st(ref FUNCTION_LIST_P TR ppFunctionList) ;
in Code file:
System.IntPtr pp = System.IntPtr.Z ero;
myClass.C_GetFu nctionList(ref pp);
func_pointer_li st fnList = (func_pointer_l ist)Marshal.Ptr ToStructure(pp, typeof(func_poi nter_list));
I get the Exception 'InvalidFuction PointerInDelega te' in the Second line (Marshel) saying
"Invalid function pointer 0x1a201000 was passed into the runtime to be converted to a delegate. Passing in invalid function pointers to be converted to delegates can cause crashes, corruption or data loss."
Do any of you have any clue as to what is the right method of doing this.....
Where am I wrong doing this...
Does the above code not gonna work...
Thanx in Advance
1 7983
Hi All,
I have a serious problem here which is bugging me for past few days.
I have a native DLL(Win32), and it exposes only on function called
GetFunctionList
Now this function takes a pointer to pointer of a Structure as an argument.
The Structure is something like
struct func_pointer_li st{
void (*fnA)(int a,int b);
int (*fnB)(float a, double b);
}
Now I have to write an Wrapper for this Native DLL in C#.
What I did was I wrote an Structure in C# containing some delegates like this....
[UnmanagedFuncti onPointer(Calli ngConvention.Wi napi)]
public delegate void pfnA(int a, int b)
[UnmanagedFuncti onPointer(Calli ngConvention.Wi napi)]
public delegate int pfnA(float a, double b)
[StructLayout(La youtKind.Sequen tial, CharSet = CharSet.Ansi)]
public struct func_pointer_li st
{
public pfnA fnA;
public pfnB fnB;
}
Now I call this Function called GetFunctionList something like this:
using FUNCTION_LIST_P TR_PTR = System.IntPtr;
[DllImport("NATI VE.DLL", CharSet = CharSet.Ansi)]
public extern static void C_GetFunctionLi st(ref FUNCTION_LIST_P TR ppFunctionList) ;
in Code file:
System.IntPtr pp = System.IntPtr.Z ero;
myClass.C_GetFu nctionList(ref pp);
func_pointer_li st fnList = (func_pointer_l ist)Marshal.Ptr ToStructure(pp, typeof(func_poi nter_list));
I get the Exception 'InvalidFuction PointerInDelega te' in the Second line (Marshel) saying
"Invalid function pointer 0x1a201000 was passed into the runtime to be converted to a delegate. Passing in invalid function pointers to be converted to delegates can cause crashes, corruption or data loss."
Do any of you have any clue as to what is the right method of doing this.....
Where am I wrong doing this...
Does the above code not gonna work...
Thanx in Advance
The problem is solved.... as of now...
What I did was just added some more Tags in the member function Defination of the structure and also added the Pack Tag in the Structure Layout... something like this:
[UnmanagedFuncti onPointer(Calli ngConvention.Wi napi)]
public delegate void pfnA(int a, int b)
[UnmanagedFuncti onPointer(Calli ngConvention.Wi napi)]
public delegate int pfnA(float a, double b)
[StructLayout(La youtKind.Sequen tial, CharSet = CharSet.Ansi , Pack=2)]
public struct func_pointer_li st
{
[MarshalAs(Unman agedType.Functi onPtr)]
public pfnA fnA;
[MarshalAs(Unman agedType.Functi onPtr)]
public pfnB fnB;
}
Possibly the problem was due to the Pack specification.. .
The rest of the Code Stands Same.... and it Worked...
Although I am stuck in some other problem, probably not a C# problem but a Domain Problem....
Anyways Thanx for the Notice...
And
Cheers
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: j-integra_support |
last post by:
Looking for Java/COM interoperability tools? Thousands of companies
world-wide are using J-Integra for COM for interoperability between
Java and Microsoft COM applications. J-Integra for COM is a pure Java
implementation of the DCOM protocol, making it several times faster
than Web Services.
J-Integra for COM Features:
* Access J2EE components from VB, C++, ASPs, etc...
* Access COM components from EJBs, Servlets, JSPs, Applets, etc......
|
by: Frederik Kesting |
last post by:
Hi!
I heard about the possibilty of using different languages for one
project whith the .Net Framework. Is it f.e. possible to include
Managed C++ code into a VB.Net project without changing syntax? Could
someone tell me more about interoperability or just give me a tutorial
link?
greetz!
|
by: Sai Kit Tong |
last post by:
Hi,
I am developing a new application running on Windows platform that needs to
interface with existing legacy code - written in basic C / C++. I am trying
to evaluate Java vs C# implementations. Originally, I have the impression
that C# should be a clear winner.
I started with Java and using the guideline from the book "Java Native
Interface". Though complex, the book provide details of the practical
implementation and potential...
|
by: Sai Kit Tong |
last post by:
Hi,
I am developing a new application running on Windows platform that needs to
interface with existing legacy code - written in basic C / C++. I am trying
to evaluate Java vs C# implementations. Originally, I have the impression
that C# should be a clear winner.
I started with Java and using the guideline from the book "Java Native
Interface". Though complex, the book provide details of the practical
implementation and potential...
|
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: An unhandled exception of
type 'System.EntryPointNotFoundException'.
This is confusing b/c if the entry point was not found, I would think I'd
get an unresolved symbol error during linking. Furthermore, I can
successfully pass void, int *, and...
| |
by: H.B. |
last post by:
Hi,
I need to make a function that can display data on my Managed C++ app and be
called by an unmanaged C++ DLL. Something like :
void Form1::Form1_Load(System::Object * sender, System::EventArgs * e)
{
MyDLLInit(MyAppDisplayFunction);
}
|
by: Lloyd Dupont |
last post by:
I have some managed C++ interacting with native DLL,
for good integration I'm setting up some function pointer in the native DLL,
passing some function pointer from the managed world.
=================
typedef void __cdecl NSLogHandler(Oid exception);
static void __cdecl ObjectiveNSLogHandler(Oid ns_str)
{
NSString^ str = dynamic_cast<NSString^>( ObjcRuntime::GetId(ns_str) );
Console::WriteLine("GNUstep.NET: "+str);
}
|
by: Peter Olcott |
last post by:
I want to make a generic interface between a scripting language and native code,
the native code and the interpreter will both be written in C++. The interpreter
will probably be implemented as a subset of C/C++, thus will have the same
syntax as C/C++.
Somehow the interpreted code must be able to store generic function pointers
because there is no way for the interpreter to know every possible function
signature in advance. I was...
|
by: Immortal Nephi |
last post by:
I would like to design an object using class. How can this class
contain 10 member functions. Put 10 member functions into member
function pointer array.
One member function uses switch to call 10 member functions. Can
switch be replaced to member function pointer array?
Please provide me an example of source code to show smart pointer
inside class. Thanks....
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
| |
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |