Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to use WINAPI functions from c#

Status
Not open for further replies.

Quilmes

Programmer
Aug 13, 2000
12
0
0
AU
Hi,

I am trying to use the WINAPI function: GetColorDirectory which is located in mscms.dll. I have done the DLLImport statement properly and i can get one of the buffers to fill. The spec for this function is:

BOOL WINAPI GetColorDirectory(
PCTSTR pMachineName,
PTSTR pBuffer,
PDWORD pdwSize
);

My code to import it is:

[DllImport("mscms.dll")]
public static extern bool GetColorDirectory(
string pMachineName,
ref string pBuffer,
ref int pdwSize);

Then i call it using:

int i = 0;
string str = "";
GetColorDirectory (null, ref str, ref i);

What happens is i is filled with an int correctly, but i can never get a result in str.

I know this is simple but i can't see what i'm doing wrong.

Thanks in advance


quilmes
 
Try pre-filling str with 1000 spaces to give the API call some memory to fill.

Chip H.
 
Hi thanks for you response..

I tried your suggestion but no luck.. Haven't had much time to fiddle though..


quilmes
 
HI
Try using A StringBuilder instead of Passing a String..
I hope that Should Work....
raghu
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top