Managed C++ & P/Invoke in a web serice

Tech-Archive recommends: Fix windows errors by optimizing your registry



I am exploring using P/Invoke to call some legacy code from our customer
contact software. I have been trying some simple test scenarios and haven't
had success. Can someone point me to an example that shows how this can be
done? Here is a snippet of code I am trying:

Header file of C++ class for web service:

[DllImport("kernel32.dll", SetLastError=true)]
extern "C" bool GetComputerName(String *name, int *len);

Class file for web service:

String __gc* callKAPIClass::HelloWorld()
{
String *p = "1234567890123456789012345678901234567890";
int len = 30;
bool rc = true;

rc = GetComputerName(p, &len);
int rc2 = Marshal::GetLastWin32Error();

return p;
}

Unfortunately, I always get an error in GetComputerName().

Mark
.



Relevant Pages

  • Re: Header files included in header files
    ... > What does the group think of the practise of including one header file ... > I have some legacy code where this has been done, ... > dependency on a module which are not required, ...
    (comp.lang.c)
  • Header files included in header files
    ... What does the group think of the practise of including one header file from ... I have some legacy code where this has been done, ... and what is accepted practise? ...
    (comp.lang.c)