Click here to Skip to main content
15,897,187 members
Home / Discussions / C#
   

C#

 
GeneralRe: A complex one..... Pin
James T. Johnson27-Apr-03 13:03
James T. Johnson27-Apr-03 13:03 
GeneralRe: A complex one..... Pin
Jon Newman27-Apr-03 13:46
Jon Newman27-Apr-03 13:46 
GeneralRe: A complex one..... Pin
Mark Smithson27-Apr-03 21:43
Mark Smithson27-Apr-03 21:43 
GeneralRe: A complex one..... Pin
Jon Newman28-Apr-03 5:51
Jon Newman28-Apr-03 5:51 
GeneralRe: A complex one..... Pin
Mark Smithson28-Apr-03 8:10
Mark Smithson28-Apr-03 8:10 
GeneralRe: A complex one..... Pin
Jon Newman28-Apr-03 11:53
Jon Newman28-Apr-03 11:53 
GeneralMarshalling char** Pin
leppie27-Apr-03 2:42
leppie27-Apr-03 2:42 
GeneralRe: Marshalling char** Pin
Stephane Rodriguez.27-Apr-03 7:25
Stephane Rodriguez.27-Apr-03 7:25 
Here is how I got it to work,

C implementation :
extern "C" __declspec(dllexport) char** foo(int *nSize);

// implementation
__declspec(dllexport) char** foo(int *nSize)
{
  *nSize = 2;
  ::MessageBox(NULL,"unmanaged foo call","message",MB_OK);

  char **lpstr = (char**) CoTaskMemAlloc( 2*sizeof(LPSTR) );
  lpstr[0] = (char*) CoTaskMemAlloc( 100 ) ;
  strcpy(lpstr[0], "string1");
  lpstr[1] = (char*) CoTaskMemAlloc( 100 ) ;
  strcpy(lpstr[1], "string2");

  return lpstr;
}


Now for the managed part,
// declaration
[DllImport(@"..\bin\foo.dll", CharSet=CharSet.Auto)]
static public extern IntPtr foo(ref int nSize); // 

// implementation
int nSize = 0;
IntPtr pData = foo(ref nSize);
for (int i=0; i<nSize; i++)
{
  IntPtr pString = Marshal.ReadIntPtr(pData, 4*i);
  MessageBox.Show( Marshal.PtrToStringAnsi(pString) );
}

GeneralRe: Marshalling char** Pin
leppie27-Apr-03 7:59
leppie27-Apr-03 7:59 
GeneralRe: Marshalling char** Pin
Stephane Rodriguez.27-Apr-03 8:05
Stephane Rodriguez.27-Apr-03 8:05 
GeneralRe: Marshalling char** Pin
leppie27-Apr-03 8:42
leppie27-Apr-03 8:42 
GeneralRe: Marshalling char** Pin
Stephane Rodriguez.27-Apr-03 9:00
Stephane Rodriguez.27-Apr-03 9:00 
GeneralImportRow Question Pin
2sky27-Apr-03 1:50
2sky27-Apr-03 1:50 
GeneralRe: ImportRow Question Pin
Andres Manggini27-Apr-03 17:44
Andres Manggini27-Apr-03 17:44 
GeneralRe: ImportRow Question Pin
2sky28-Apr-03 8:09
2sky28-Apr-03 8:09 
Generalquestion about treeview control Pin
Robin Vane26-Apr-03 20:53
Robin Vane26-Apr-03 20:53 
GeneralRe: question about treeview control Pin
Meysam Mahfouzi27-Apr-03 17:13
Meysam Mahfouzi27-Apr-03 17:13 
GeneralIIS's FTP Pin
paulwhygle26-Apr-03 16:21
paulwhygle26-Apr-03 16:21 
GeneralRe: IIS's FTP Pin
Ray Cassick26-Apr-03 18:44
Ray Cassick26-Apr-03 18:44 
QuestionProgressBar -Simple???? Pin
gman4426-Apr-03 14:14
gman4426-Apr-03 14:14 
AnswerRe: ProgressBar -Simple???? Pin
Jon Newman27-Apr-03 6:23
Jon Newman27-Apr-03 6:23 
AnswerRe: ProgressBar -Simple???? Pin
Richard Deeming29-Apr-03 1:09
mveRichard Deeming29-Apr-03 1:09 
GeneralContinuous Stream of MouseMove Messages!!! Pin
Waleed Eissa26-Apr-03 12:50
Waleed Eissa26-Apr-03 12:50 
GeneralPaintDesktop() Pin
Waleed Eissa26-Apr-03 12:42
Waleed Eissa26-Apr-03 12:42 
General3rd party control Pin
Kant26-Apr-03 6:08
Kant26-Apr-03 6:08 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.