DLLImport and Marshalling

S

Simon

Hi all,

I am trying to call a function from a dll and it has the following
prototype.

int foo(int *argc, char ***argv) or int foo(int *argc, char *argv[])

I am having problems that I assume are to do with marshalling. I am
using

[DllImport("some.dll")]
int foo(IntPtr argc, string[] argv)

But this is failing. Am I missing something somewhere? Am I making a
blindingly obvious mistake.

TIA for your help.

Simon
 
D

Dmytro Lapshyn [MVP]

Hey Simon,

First of all, this should at least be:

[DllImport("some.dll")]
int foo(ref int argc, string[] argv)

As for the second argument, can you please check that the C++ declaration is
int foo(int *argc, char ***argv)

or still

int foo(int *argc, char **argv) ?

--
Sincerely,
Dmytro Lapshyn [Visual Developer - Visual C# MVP]


Simon said:
Hi all,

I am trying to call a function from a dll and it has the following
prototype.

int foo(int *argc, char ***argv) or int foo(int *argc, char *argv[])

I am having problems that I assume are to do with marshalling. I am
using

[DllImport("some.dll")]
int foo(IntPtr argc, string[] argv)

But this is failing. Am I missing something somewhere? Am I making a
blindingly obvious mistake.

TIA for your help.

Simon
 
S

s.p.nee

Thanks for the quick reply Dmytro.

Yes the declaration is definitely.

int foo(int *argc, char ***argv) .

It is the initialization funtion of the MPI library, the following it
cut and paste from the header.

int MPI_Init(int *argc, char ***argv)

Thanks

Simon
 
S

s.p.nee

Thanks I have now solved this with Dmytro's pointing me in the right
direction.

For those interested. The answer to my problem was

[DllImport("mpich.dll", EntryPoint="MPI_Init")]
private static extern int MPI_Init(ref int argc , ref string[] arg);

Thanks Dmytro.

Simon
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top