473,394 Members | 1,765 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,394 software developers and data experts.

Function Declarations and CDecl

Hi all

I am relatively new to C# programming and have run into a problem that I believe is caused by my C# function declarations. I believe that my C# function must use a CDecl CallingConvention but I do not know how to set this

I am attempting to have a C style DLL perform a Callback to a given function in my C# class passing a pointer to a struct. Currently, I have the callback working ( that is I get my expected events ) but the problem is that my variable ( Pointer to Struct ) is always NULL

ex
private unsafe int my_event_handler(SK_Event *ptr_event, void *pvoid_tag

// ptr_event is always NUL
if ( ptr_event != null

Console.WriteLine("Handler: " + ptr_event->Data.ToString())


I have read numerous articles on managed / unmanaged code using the Marshal class etc. and have seen many different combinations of Attributes and directives that can be applied. My question is, is there a way to force your C# function to have a particular CallingConvention ? ...I have seen how to use this with my DLLImportAttribute but have not been able to apply this to a C# method / delegate function. ...Or Is this even possible

Any help would be appreicated

Thanks in advance
Boot

Nov 16 '05 #1
3 2927
Boots,

I don't believe that tis is possible. By default, I believe that
managed callbacks exported by .NET use the STDCALL calling convention. I am
not sure if in the next version this will be addressed.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Boots" <bo***********@hotmail.com> wrote in message
news:77**********************************@microsof t.com...
Hi all,

I am relatively new to C# programming and have run into a problem that I believe is caused by my C# function declarations. I believe that my C#
function must use a CDecl CallingConvention but I do not know how to set
this.
I am attempting to have a C style DLL perform a Callback to a given function in my C# class passing a pointer to a struct. Currently, I have
the callback working ( that is I get my expected events ) but the problem is
that my variable ( Pointer to Struct ) is always NULL.
ex:
private unsafe int my_event_handler(SK_Event *ptr_event, void *pvoid_tag)
{
// ptr_event is always NULL
if ( ptr_event != null )
{
Console.WriteLine("Handler: " + ptr_event->Data.ToString());
}

}

I have read numerous articles on managed / unmanaged code using the Marshal class etc. and have seen many different combinations of Attributes
and directives that can be applied. My question is, is there a way to force
your C# function to have a particular CallingConvention ? ...I have seen
how to use this with my DLLImportAttribute but have not been able to apply
this to a C# method / delegate function. ...Or Is this even possible ?
Any help would be appreicated!

Thanks in advance,
Boots

Nov 16 '05 #2
I have read numerous articles on managed / unmanaged code using the
Marshal class etc. and have seen many different combinations of
Attributes and directives that can be applied. My question is, is
there a way to force your C# function to have a particular
CallingConvention ? ...I have seen how to use this with my
DLLImportAttribute but have not been able to apply this to a C#
method / delegate function. ...Or Is this even possible ?


Yes. But it's not so "nice" like adding an Attribute.

See http://groups.google.com/groups?selm...%40tkmsftngp03 for
details.

Does it work now?

mfg GP

Nov 16 '05 #3
Thanx for the reply Gunter, you weren't kidding though - it's not a nice looking solution ! :
I'll try to stumble my way through this and I'll let you know how it goes

Thanx again for your help
Nov 16 '05 #4

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

Similar topics

3
by: Jason | last post by:
char * const * (*fn)(void); Seems rarther confusing to me, becuase of the way const can be used, like this: const char * a; /* pointer to const char */ char const * a; /* pointer to const...
5
by: Alfonso Morra | last post by:
Hi all, I came accross this FP signature and it has me baffled. Can anyone explain this signature to me - i.e what are the input and output types ? void(*(*foo)(int))(int,void(*)(int)) ...
19
by: sabarish | last post by:
Hi friend, what is the use of function pointer in c language and where it is useful? tell with simple example...? plz help me.
8
by: kurtcobain1978 | last post by:
-------------------------------------------------------------------------------- I need to do the exactly same thing in VB.NET. Load a unmanaged C DLL dynamically and then call a function in...
17
by: I.M. !Knuth | last post by:
Hi. I'm more-or-less a C newbie. I thought I had pointers under control until I started goofing around with this: ...
3
by: Rav | last post by:
hi, i need a function, preferably a program for parsing the complex declarations in C. Can anyone help me in this regard...i appreciate. i work on Turbo C++ 3.0 in windows environment. Also, plz...
12
by: Googy | last post by:
Hi!! Can any one explain me the meaning of following notations clearly : 1. typedef char(*(*frpapfrc()))(); frpapfrc f; 2. typedef int (*(arr2d_ptr)()); arr2d_ptr p; 3. typedef int...
26
by: aruna.mysore | last post by:
Hi all, I have a specific problem passing a function pointer array as a parameter to a function. I am trying to use a function which takes a function pointer array as an argument. I am too sure...
2
by: =?Utf-8?B?dmxhZGltaXI=?= | last post by:
Hi, i have big subsystem written in old C and published by dll (and lib). Dll functions do: 1) allocate global memory for internal structures 2) controls dll subsystem (communicate by sockets,...
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...
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...

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.