From: Tom Shelton on
Jason Keats used his keyboard to write :
> 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?
>
> I'm pretty sure you can't directly access functions within the static library
> file aesra10.lib.
>
> You will first need to use C/C++ to link it into a dynamic (.dll) library of
> your making. You should then be able to use P/Invoke from C# to access its
> functions.
>
> Once you've made a dll you should put it in the same folder as your program.

In that case, it would be easier to just create a C++/CLI assembly:

http://tom-shelton.net/index.php/2008/12/

Then you can just reference it like any other managed assembly...

--
Tom Shelton


From: Jeff Johnson on

"Doug Forster" <dougremovethis(a)tonandthisiq.co.nz> wrote in message
news:uCVD19NCLHA.5808(a)TK2MSFTNGP02.phx.gbl...

>> That does not look like correct C to me. Parens are used only for
>> function declarations and calls when paired with an identifier (they are
>> also, of course, used for certain program statements and expression
>> grouping).
>
> It's perfectly correct C but it doesn't mean what the OP thinks. If that
> really is the declaration then it means a pointer to a function with no
> parameters that returns a double result.

I was going to put that in my reply and then I thought, "Nah, that couldn't
be...."


From: Peter Duniho on
Doug Forster wrote:
>>
>> That does not look like correct C to me. Parens are used only for
>> function declarations and calls when paired with an identifier (they are
>> also, of course, used for certain program statements and expression
>> grouping).
>
> It's perfectly correct C but it doesn't mean what the OP thinks. If that
> really is the declaration then it means a pointer to a function with no
> parameters that returns a double result.

Huh. Since when has C/C++ allowed the omission of the * in function
pointer declarations? Is that new in the last ten years or so?

You're right, the code compiles just fine with both VS and gcc. But
I've never seen function pointers declared that way in C/C++, and I
can't even find that syntax documented in the usual places I'm in the
habit of looking (for example, the MSDN page documenting pointer syntax
— http://msdn.microsoft.com/en-us/library/89e4h321(v=VS.100).aspx — only
has the * version, with no mention at all of the alternative).

I've always hated the "int (*foo)(void)" syntax; I wish I'd known I
could have always just been writing "int foo(void)" as the type! Of
course, now almost all the code I write is in C# and I don't have to
deal with C/C++'s clunky syntax. But it would've been nice "in the old
days". :)

Pete
From: Arne Vajhøj on
On 11-06-2010 04:02, Peter Duniho wrote:
> Doug Forster wrote:
>>>
>>> That does not look like correct C to me. Parens are used only for
>>> function declarations and calls when paired with an identifier (they are
>>> also, of course, used for certain program statements and expression
>>> grouping).
>>
>> It's perfectly correct C but it doesn't mean what the OP thinks. If
>> that really is the declaration then it means a pointer to a function
>> with no parameters that returns a double result.
>
> Huh. Since when has C/C++ allowed the omission of the * in function
> pointer declarations? Is that new in the last ten years or so?
>
> You're right, the code compiles just fine with both VS and gcc. But I've
> never seen function pointers declared that way in C/C++, and I can't
> even find that syntax documented in the usual places I'm in the habit of
> looking (for example, the MSDN page documenting pointer syntax —
> http://msdn.microsoft.com/en-us/library/89e4h321(v=VS.100).aspx — only
> has the * version, with no mention at all of the alternative).
>
> I've always hated the "int (*foo)(void)" syntax; I wish I'd known I
> could have always just been writing "int foo(void)" as the type! Of
> course, now almost all the code I write is in C# and I don't have to
> deal with C/C++'s clunky syntax. But it would've been nice "in the old
> days". :)

The C89 standard says:

<quote>
To pass one function to another, one might say

int f(void);
/*...*/
g(f);

Note that f must be declared explicitly in the calling function, as
its appearance in the expression g(f) was not followed by ( . Then
the definition of g might read

g(int (*funcp)(void))
{
/*...*/ (*funcp)() /* or funcp() ... */
}

or, equivalently,

g(int func(void))
{
/*...*/ func() /* or (*func)() ... */
}

</quote>

Arne

From: Peter Duniho on
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.

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).

Anyway, thanks for the info.

Pete
First  |  Prev  |  Next  |  Last
Pages: 1 2 3
Prev: C# NG in de.comp.lang.* ??? New Info!
Next: Compare tool