DLLImport and Marshalling

  • Thread starter Thread starter Simon
  • Start date Start date
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
 
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
 
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
 
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
 
Back
Top