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

function pointer

I'm using an external DLL that expects the address of a function for a
callback. How can I go about getting the address of a function I have?
Thanks for any help in this.

Lance Johnson
Nov 16 '05 #1
8 4240
you have to declare delegate

public delegate void TestCallback();

and pass it as a parameter to the function in DllImport.

[DllImport("Sample.dll")]
public static extern void SomeFunction(TestCallback callback);

--
Shak
(Houston)
"Lance Johnson" <lj******@docs.com> wrote in message
news:#O**************@tk2msftngp13.phx.gbl...
I'm using an external DLL that expects the address of a function for a
callback. How can I go about getting the address of a function I have?
Thanks for any help in this.

Lance Johnson

Nov 16 '05 #2
Thanks for the reply. I believe this assumes it's just a regular function.
However, the function in the external DLL is a member function. Is there
anything special I have to do for that to work because I'm not just calling
a particular function but instead a function on an instance of some class.

Lance Johnson
"Shakir Hussain" <sh**@fakedomain.com> wrote in message
news:O1**************@TK2MSFTNGP09.phx.gbl...
you have to declare delegate

public delegate void TestCallback();

and pass it as a parameter to the function in DllImport.

[DllImport("Sample.dll")]
public static extern void SomeFunction(TestCallback callback);

--
Shak
(Houston)
"Lance Johnson" <lj******@docs.com> wrote in message
news:#O**************@tk2msftngp13.phx.gbl...
I'm using an external DLL that expects the address of a function for a
callback. How can I go about getting the address of a function I have?
Thanks for any help in this.

Lance Johnson


Nov 16 '05 #3
When you pass structures or callbacks to Api's using DllImport, you have to
create a Managed code by duplicating the structure or function in c#. You
have to use those to the function to handle things. Refer MSDN hpw to do
that.

--
Shak
(Houston)
"Lance Johnson" <lj******@docs.com> wrote in message
news:O7**************@tk2msftngp13.phx.gbl...
Thanks for the reply. I believe this assumes it's just a regular function. However, the function in the external DLL is a member function. Is there
anything special I have to do for that to work because I'm not just calling a particular function but instead a function on an instance of some class.

Lance Johnson
"Shakir Hussain" <sh**@fakedomain.com> wrote in message
news:O1**************@TK2MSFTNGP09.phx.gbl...
you have to declare delegate

public delegate void TestCallback();

and pass it as a parameter to the function in DllImport.

[DllImport("Sample.dll")]
public static extern void SomeFunction(TestCallback callback);

--
Shak
(Houston)
"Lance Johnson" <lj******@docs.com> wrote in message
news:#O**************@tk2msftngp13.phx.gbl...
I'm using an external DLL that expects the address of a function for a
callback. How can I go about getting the address of a function I have? Thanks for any help in this.

Lance Johnson



Nov 16 '05 #4
I don't know what you mean by hpw and when I do a search for hpw it returns
nothing.

Lance Johnson

"Shakir Hussain" <sh**@fakedomain.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
When you pass structures or callbacks to Api's using DllImport, you have to create a Managed code by duplicating the structure or function in c#. You
have to use those to the function to handle things. Refer MSDN hpw to do
that.

--
Shak
(Houston)
"Lance Johnson" <lj******@docs.com> wrote in message
news:O7**************@tk2msftngp13.phx.gbl...
Thanks for the reply. I believe this assumes it's just a regular

function.
However, the function in the external DLL is a member function. Is there
anything special I have to do for that to work because I'm not just

calling
a particular function but instead a function on an instance of some class.
Lance Johnson
"Shakir Hussain" <sh**@fakedomain.com> wrote in message
news:O1**************@TK2MSFTNGP09.phx.gbl...
you have to declare delegate

public delegate void TestCallback();

and pass it as a parameter to the function in DllImport.

[DllImport("Sample.dll")]
public static extern void SomeFunction(TestCallback callback);

--
Shak
(Houston)
"Lance Johnson" <lj******@docs.com> wrote in message
news:#O**************@tk2msftngp13.phx.gbl...
> I'm using an external DLL that expects the address of a function for a > callback. How can I go about getting the address of a function I

have? > Thanks for any help in this.
>
> Lance Johnson
>
>



Nov 16 '05 #5
Sorry,

it was a typo, i meant

Refer MSDN how to do that

--
Shak
(Houston)
"Lance Johnson" <lj******@docs.com> wrote in message
news:ed**************@TK2MSFTNGP11.phx.gbl...
I don't know what you mean by hpw and when I do a search for hpw it returns nothing.

Lance Johnson

"Shakir Hussain" <sh**@fakedomain.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
When you pass structures or callbacks to Api's using DllImport, you have to
create a Managed code by duplicating the structure or function in c#. You
have to use those to the function to handle things. Refer MSDN hpw to do
that.

--
Shak
(Houston)
"Lance Johnson" <lj******@docs.com> wrote in message
news:O7**************@tk2msftngp13.phx.gbl...
Thanks for the reply. I believe this assumes it's just a regular

function.
However, the function in the external DLL is a member function. Is

there anything special I have to do for that to work because I'm not just

calling
a particular function but instead a function on an instance of some class.
Lance Johnson
"Shakir Hussain" <sh**@fakedomain.com> wrote in message
news:O1**************@TK2MSFTNGP09.phx.gbl...
> you have to declare delegate
>
> public delegate void TestCallback();
>
> and pass it as a parameter to the function in DllImport.
>
> [DllImport("Sample.dll")]
> public static extern void SomeFunction(TestCallback callback);
>
> --
> Shak
> (Houston)
>
>
> "Lance Johnson" <lj******@docs.com> wrote in message
> news:#O**************@tk2msftngp13.phx.gbl...
> > I'm using an external DLL that expects the address of a function
for a > > callback. How can I go about getting the address of a function I

have?
> > Thanks for any help in this.
> >
> > Lance Johnson
> >
> >
>
>



Nov 16 '05 #6
You may try to search in the framework.interop newsgroup as well.

Sunny
Nov 16 '05 #7
If your "function" is a method of a native C++ class in an external DLL,
then you can't call it directly.
One possible option is to create a managed wrapper class using VS2003's
Managed Extentions for C++ and populate the class with thunk methods that
invoke the associated native method(s).

Willy.
"Lance Johnson" <lj******@docs.com> wrote in message
news:O7**************@tk2msftngp13.phx.gbl...
Thanks for the reply. I believe this assumes it's just a regular
function.
However, the function in the external DLL is a member function. Is there
anything special I have to do for that to work because I'm not just
calling
a particular function but instead a function on an instance of some class.

Lance Johnson
"Shakir Hussain" <sh**@fakedomain.com> wrote in message
news:O1**************@TK2MSFTNGP09.phx.gbl...
you have to declare delegate

public delegate void TestCallback();

and pass it as a parameter to the function in DllImport.

[DllImport("Sample.dll")]
public static extern void SomeFunction(TestCallback callback);

--
Shak
(Houston)
"Lance Johnson" <lj******@docs.com> wrote in message
news:#O**************@tk2msftngp13.phx.gbl...
> I'm using an external DLL that expects the address of a function for a
> callback. How can I go about getting the address of a function I have?
> Thanks for any help in this.
>
> Lance Johnson
>
>



Nov 16 '05 #8
If your "function" is a method of a native C++ class in an external DLL,
then you can't call it directly.
One possible option is to create a managed wrapper class using VS2003's
Managed Extentions for C++ and populate the class with thunk methods that
invoke the associated native method(s).

Willy.
"Lance Johnson" <lj******@docs.com> wrote in message
news:O7**************@tk2msftngp13.phx.gbl...
Thanks for the reply. I believe this assumes it's just a regular
function.
However, the function in the external DLL is a member function. Is there
anything special I have to do for that to work because I'm not just
calling
a particular function but instead a function on an instance of some class.

Lance Johnson
"Shakir Hussain" <sh**@fakedomain.com> wrote in message
news:O1**************@TK2MSFTNGP09.phx.gbl...
you have to declare delegate

public delegate void TestCallback();

and pass it as a parameter to the function in DllImport.

[DllImport("Sample.dll")]
public static extern void SomeFunction(TestCallback callback);

--
Shak
(Houston)
"Lance Johnson" <lj******@docs.com> wrote in message
news:#O**************@tk2msftngp13.phx.gbl...
> I'm using an external DLL that expects the address of a function for a
> callback. How can I go about getting the address of a function I have?
> Thanks for any help in this.
>
> Lance Johnson
>
>



Nov 16 '05 #9

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

Similar topics

58
by: jr | last post by:
Sorry for this very dumb question, but I've clearly got a long way to go! Can someone please help me pass an array into a function. Here's a starting point. void TheMainFunc() { // Body of...
37
by: Ben | last post by:
Hi, there. Recently I was working on a problem where we want to save generic closures in a data structure (a vector). The closure should work for any data type and any method with pre-defined...
2
by: sushil | last post by:
+1 #include<stdio.h> +2 #include <stdlib.h> +3 typedef struct +4 { +5 unsigned int PID; +6 unsigned int CID; +7 } T_ID; +8 +9 typedef unsigned int (*T_HANDLER)(void); +10
27
by: Marlene Stebbins | last post by:
I am experimenting with function pointers. Unfortunately, my C book has nothing on function pointers as function parameters. I want to pass a pointer to ff() to f() with the result that f() prints...
23
by: bluejack | last post by:
Ahoy... before I go off scouring particular platforms for specialized answers, I thought I would see if there is a portable C answer to this question: I want a function pointer that, when...
3
by: Beta What | last post by:
Hello, I have a question about casting a function pointer. Say I want to make a generic module (say some ADT implementation) that requires a function pointer from the 'actual/other modules'...
54
by: John | last post by:
Is the following program print the address of the function? void hello() { printf("hello\n"); } void main() { printf("hello function=%d\n", hello); }
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...
20
by: MikeC | last post by:
Folks, I've been playing with C programs for 25 years (not professionally - self-taught), and although I've used function pointers before, I've never got my head around them enough to be able to...
10
by: Richard Heathfield | last post by:
Stephen Sprunk said: <snip> Almost. A function name *is* a pointer-to-function. You can do two things with it - copy it (assign its value to an object of function pointer type, with a...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.