saddy

Hi,

I am working on a gpsdevice enad i wanted to get nmea string, i know that i must creat file with the fonction CreateFile and give the return handle to ReadFile but i don't even knwo to invoke it and how to get from it because it return bool variable.

Please help!!!!!!

This the code that used for create file:

//Flags

private const uint GENERIC_READ = 0x80000000;

private const uint FILE_SHARE_READ = 0x1;

private const uint CREATE_ALWAYS = 2;

private System.IntPtr handle;

public bool Open(string FileName)

{

// open the existing file for reading

handle = CreateFile(FileName, GENERIC_READ, FILE_SHARE_READ, 0, CREATE_ALWAYS, 0, System.IntPtr.Zero);

if (handle != System.IntPtr.Zero)

{

return true;

}

else

{

return false;

}

}

public bool Close()

{

return CloseHandle(handle);

}

#region PInvokes to coredll.dll

[DllImport("Kernel32.dll",SetLastError=true, CharSet=CharSet.Auto)]

static extern IntPtr CreateFile(

string filename,

uint fileaccess,

uint fileshare,

uint securityattributes,

uint creationdisposition,

int flags,

IntPtr template);



Re: Visual C# General get nmea string

Mark Dawson

Hi,

you can just change the return type of the Open method to be IntPtr, since that is the handle to the file, callers of this function can then check this value to see if the open succeeded.

Mark.






Re: Visual C# General get nmea string

saddy

theCreateFile function return a handle that i passin parameter to readfile but it doesn't tell me how toget string information of the file.

Please help i am lost!!





Re: Visual C# General get nmea string

Mark Dawson

Hi,

so your issue is that you are not sure how to use the ReadFile function If so then this link has the PInvoke signature and an example of how to use the method: http://www.pinvoke.net/default.aspx/kernel32/ReadFile.html

Mark.