Converting to Unicode
StrConv(sServer, vbUnicode)
Can anybody tell me how to do this in c#?
StrConv(sServer, vbUnicode)
Can anybody tell me how to do this in c#?
Strings in .NET are always stored as Unicode and therefore there is no need to convert an existing string (already stored in Unicode) to Unicode.
Depending on what you are trying to achieve in the bigger picture, you may need to look at the members of the System.Text.Encoding class.
vb6:
NetFileClose StrConv(sServer, vbUnicode), fi3.fi3_id
c#: NetFileClose(strServer, pCurrent.fi3_id);
byte
NetFileClose(data.ToString(), pCurrent.fi3_id);
You shouldn't need to do any conversion, having a look at the PInvoke signature on pinvoke.net (http://pinvoke.net/default.aspx/netapi32/NetFileClose.html), it just takes a standard string, .NET will worry about the marshalling.
The server name that you pass to NetFileClose requires that it be prefixed with "\\", are you doing this?
If you are hardcoding the server name within the code, remember that you will need to escape the backslashes, ie:
string name = "\\\\MyServer"; // Represents \\MyServer
or
string name = @"\\MyServer"; // Represents \\MyServer
const
int MAX_PREFERRED_LENGTH = -1; int dwReadEntries; int dwTotalEntries;IntPtr pBuffer = IntPtr.Zero ;
FILE_INFO_3 pCurrent =
new FILE_INFO_3(); string strServer = @"\\Javanew1.osiris.net"; //get list of open files int dwStatus = NetFileEnum(strServer, null, null, 3, ref pBuffer, MAX_PREFERRED_LENGTH, out dwReadEntries, out dwTotalEntries, IntPtr.Zero ); if (dwStatus == 0){
for (int dwIndex=0; dwIndex < dwReadEntries; dwIndex++){
IntPtr iPtr =
new IntPtr(pBuffer.ToInt32() + (dwIndex * Marshal.SizeOf(pCurrent)));pCurrent = (FILE_INFO_3) Marshal.PtrToStructure(iPtr,
typeof(FILE_INFO_3));lvAssets.Items.Add((
string)(pCurrent.fi3_pathname)); if (pCurrent.fi3_pathname.Substring(pCurrent.fi3_pathname.Length-4, 4) == ".doc"){
NetFileClose(strServer, pCurrent.fi3_id);
Globals.WriteLog("!!! User Disconnected" + " " + pCurrent.fi3_username + " " + pCurrent.fi3_id + " " + pCurrent.fi3_permission + " " + pCurrent.fi3_pathname, Globals.strCubeLogFile);
sbStatus.Text = "User Disconnected" + " " + pCurrent.fi3_username + " " + pCurrent.fi3_id + " " + pCurrent.fi3_permission + " " + pCurrent.fi3_pathname;
}
}
NetApiBufferFree(pBuffer);
}
While I haven't tried running your code, I would recommend running your application with CLRSpy - specifically the Marshalling Customer Debug Probe. It may be that there is a marshalling issue with the PInvoke calls.
Adam Nathan talks about CLR Spy on his CLR Interop Blog on MSDN: http://blogs.msdn.com/adam_nathan/archive/2004/01/13/58308.aspx
Hope that helps,
Stephen
http://blogs.msdn.com/stfisher