From: Arne Vajhøj on
On 12-06-2010 01:01, Peter Duniho wrote:
> Arne Vajhøj wrote:
>> The C89 standard says:
>>
>> <quote>
>> [...]
>> or, equivalently,
>>
>> g(int func(void))
>> {
>> /*...*/ func() /* or (*func)() ... */
>> }
>>
>> </quote>
>
> Well, I did learn C and was using function pointers before 1989. So I
> guess it wasn't technically part of the established language at that time.

It may even have been working before that. C89 was the first officially
C standard.

But I don't have a copy of K&R from before 1989 to check.

> But still, that second syntax is so much nicer, I'm bewildered why it
> isn't more commonly used (and of course, how I managed to go all this
> time without ever even seeing it).

If I were to guess then people prefer the * syntax because
we call it a function pointer.

Arne
From: Peter Duniho on
Arne Vajhøj wrote:
> It may even have been working before that. C89 was the first officially
> C standard.
>
> But I don't have a copy of K&R from before 1989 to check.

My 2nd edition copy, copyright 1988, makes no mention of it (yet, does
have "ANSI C" written prominently over the cover as part of the
artwork). It does discuss the "new" syntax of _calling_ functions
through a pointer in which the * is omitted, but not of declaring the
variables that way.

I agree that there were probably C compilers even before that, that
allowed the no-* syntax. It seems like a lot of "new" features in C
came about after they were first seen in one compiler or another (there
lacking a real standard). But it surely wasn't widely known.

>> But still, that second syntax is so much nicer, I'm bewildered why it
>> isn't more commonly used (and of course, how I managed to go all this
>> time without ever even seeing it).
>
> If I were to guess then people prefer the * syntax because
> we call it a function pointer.

A fine guess, except that it is very common practice to typedef function
pointers specifically so one does _not_ have to deal with the * (well,
and all the other stuff too…I admit it's not entirely just about the *).

I'm not sure there really is that much of an aversion among C
programmers to using pointer types that don't actually make one type the *.

That said, I haven't got any better guesses, so I suppose I'll just have
to remain bewildered. :)

Pete
From: Arne Vajhøj on
On 12-06-2010 13:06, Peter Duniho wrote:
> Arne Vajhøj wrote:
>>> But still, that second syntax is so much nicer, I'm bewildered why it
>>> isn't more commonly used (and of course, how I managed to go all this
>>> time without ever even seeing it).
>>
>> If I were to guess then people prefer the * syntax because
>> we call it a function pointer.
>
> A fine guess, except that it is very common practice to typedef function
> pointers specifically so one does _not_ have to deal with the * (well,
> and all the other stuff too…I admit it's not entirely just about the *).

But then there would typically be something in the new name that
indicates the same (ROUTINE or PROC is common in Win32 API).

> That said, I haven't got any better guesses, so I suppose I'll just
> have to remain bewildered. :)

Maybe someone wrote a function pointer tutorial back in the 70's or 80's
using the common syntax and lots of people learned from that and the
next generation of programmers learned from them and the next
generation again ... and so on.

Arne
From: Peter Duniho on
Arne Vajhøj wrote:
> [...]
> Maybe someone wrote a function pointer tutorial back in the 70's or 80's
> using the common syntax and lots of people learned from that and the
> next generation of programmers learned from them and the next
> generation again ... and so on.

Maybe. Thanks goodness that never happens in the C# community!

;)
From: ping235 on
u need:
1, pack the lib and .h file into a dll and export all the methods u want.
2, translate ur c methods into its c# equivalent with P/Invoke.

P.S. c# equivalent of extern void standardCalc(double param(), double
inputs(), double outputs()) is:

[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
delegate double CallBack();
extern void standardCalc(CallBack param, CallBack inputs, CallBack outputs);

the parameter of attribute UnmanagedFunctionPointer depends on the
calling convention of ur function pointer.

ping235

On 2010/6/10 20:05, jp2msft wrote:
> I've got a library from a government agency that only comes with the .lib and
> a header (.h) file.
>
> The header shows me what methods are exposed, but I'm not sure if I can get
> to those features through a .Net Framework.
>
> If I want to call one of the four (4) exported methods of the DLL, how would
> I go about formatting the P/Invoke call to them?
>
> Here is an example of one of the exposed methods (from the header):
>
> extern void standardCalc(double param(), double inputs(), double outputs());
>
> I'm getting rather used to C# syntax, but I think "double param()" is an
> array of doubles - what I'd call "double[] param" in C#. If I am mistaken,
> please correct me!
>
> So, how would I go about invoking this exposed method from the library file
> "aesra10.lib"?
>
> Also, all examples of P/Invoke only list the file name, not it's location.
> Do all files that I invoke this way have to be in a certain folder or can I
> direct it to the folder where my application will be storing this DLL?