This message was discovered on microsoft.public.dotnet.framework.interop.
| Claire Reed |
Hi there,
Has anyone managed to use the rapi functions in VB.Net? I have referenced the DLL functions using:
Declare Auto Function CeRapiInit Lib "rapi.dll" () As Long Declare Auto Function CeGetLastError Lib "rapi.dll" () As Long Declare Auto Function CeRapiUninit Lib "rapi.dll" () As Long Declare Auto Function CeFindFirstFile Lib "rapi.dll" (ByVal strFileName As String, _ ByVal typFindFileData As RemoteCETypeLibrary.CE_FIND_DATA) As Long Declare Auto Function CeFindClose Lib "rapi.dll" (ByVal lngFindFile As Long) As Long Declare Auto Function CeRapiInitEx Lib "rapi.dll" (ByVal typRapiInit As RemoteCETypeLibrary.RAPIINIT) As Long
and also have a reference to the RemoteCE type library produced by www.conduits.com. However, when I imported the Remote CE type library (RemoteCE.tlb) only the constants were imported and not the methods (hence why I have also used the Declare functions).
When I run the code to initialise Rapi:
Dim lngRetVal As Long lngRetVal = CeRapiInit()
then I have an invalid error number returned.
Does anyone have any pointers/sample code for vb.net? The only sample code I have is in VB6.
My aim is to write an application which will enable the user to copy files from their handheld to their PC by just pushing one button.
regards
Claire
|
|
|
| |
|
| |
| |
| D Christensen |
Hi,
Haven't checked your code, but here's the wrapper I'm using in C#. I have only used the Init + registry functions myself so the Create/Writefile API's havent been tested. I'm only using rapi.dll, no wrappers.
I'm using the following higher-level wrappers for RAPI Init/Uninit.
public bool InitDevice(int nTimeout) { RAPIINIT ri = new RAPIINIT(); ri.cbsize = System.Runtime.InteropServices.Marshal.SizeOf(ri); uint hRes = CeRapiInitEx(ref ri);
ManualResetEvent me = new ManualResetEvent(false); me.Handle = ri.heRapiInit;
if (!me.WaitOne(nTimeout, true)) { CeRapiUninit(); return false; } else { return true; } }
public void UninitDevice() { CeRapiUninit(); }
I hope you can translate this into VB.NET.
Best regards,
Dag Christensen
---
public enum RegistryHive : uint { HKEY_CLASSES_ROOT = 0x80000000, HKEY_CURRENT_USER = 0x80000001, HKEY_LOCAL_MACHINE = 0x80000002 }
public enum RegistryValueType : int { REG_DWORD = 4, // 32-bit number REG_SZ = 1, // Unicode null terminated string REG_MULTI_SZ = 7 // Multiple Unicode strings }
[StructLayout(LayoutKind.Explicit)] private struct RAPIINIT { [FieldOffset(0)] public int cbsize; [FieldOffset(4)] public System.IntPtr heRapiInit; [FieldOffset(8)] public System.IntPtr hrRapiInit; };
[DllImport("rapi.dll", CharSet=CharSet.Unicode)] private static extern int CeCreateFile( string lpFileName, uint dwDesiredAccess, uint dwShareMode, uint lpSecurityAttributes, uint dwCreationDisposition, uint dwFlagsAndAttributes, uint hTemplateFile);
[DllImport("rapi.dll", CharSet=CharSet.Unicode)] private static extern uint CeWriteFile( int hFile, byte[] lpBuffer, uint nNumberOfBytesToWrite, ref uint nNumberOfBytesWritten, uint lpOverlapped);
[DllImport("rapi.dll")] private static extern bool CeCloseHandle( int hObject );
[DllImport("rapi.dll")] private static extern uint CeRapiUninit();
[DllImport("rapi.dll")] private static extern uint CeRapiInit();
[DllImport("rapi.dll")] private static extern uint CeRapiInitEx(ref RAPIINIT pRapiInit);
[DllImport("rapi.dll", CharSet=CharSet.Unicode)] private static extern uint CeRegOpenKeyEx(uint HKEY, string lpSubKey, int ulOptions, int samDesired, out uint phkResult);
/* CeRegQueryValueEx variants */ [DllImport("rapi.dll", CharSet=CharSet.Unicode, ExactSpelling=true)] private static extern uint CeRegQueryValueEx(uint hKey, string lpValueName, int lpReserved, ref int lpType, int pValue, ref int lpchData);
[DllImport("rapi.dll", CharSet=CharSet.Unicode, ExactSpelling=true)] private static extern uint CeRegQueryValueEx(uint hKey, string lpValueName, int lpReserved, ref int lpType, StringBuilder pValue, ref int lpchData);
[DllImport("rapi.dll", CharSet=CharSet.Unicode, ExactSpelling=true)] private static extern uint CeRegQueryValueEx(uint hKey, string lpValueName, int lpReserved, ref int lpType, ref uint pValue, ref int lpchData);
/* CeRegSetValueEx variants */ [DllImport("rapi.dll", CharSet=CharSet.Unicode, ExactSpelling=true)] private static extern uint CeRegSetValueEx(uint hKey, string lpValueName, int lpReserved, int dwType, ref uint lpData, int cbData);
[DllImport("rapi.dll", CharSet=CharSet.Unicode, ExactSpelling=true)] private static extern uint CeRegSetValueEx(uint hKey, string lpValueName, int lpReserved, int dwType, StringBuilder lpData, int cbData);
[DllImport("rapi.dll")] private static extern uint CeRegCloseKey(uint hkey);
[DllImport("kernel32.dll")] private static extern uint WaitForSingleObject(int hHandle, int timeout);
|
|
|
| |
|
| |
|
| |
| steve dk |
(Type your message here) HI, First sorry for my english thats is no as good as would like. Second, don't forget that data type in ,net are diferent than in VB6, so...... if you declare a function returning a "long" in .net you really are declaring a function returning a 64 bit word. Thats completely incorrect for the rapi functions, yo must declare the function as follow: In .net Declare Auto Function CeRapiInit Lib "rapi.dll" () As integer In VB6 Declare Auto Function CeRapiInit Lib "rapi.dll" () As Long
I had exactly the same problem and took me long time to find the reason.
See u I hope this will help Steve
-------------------------------- From: steve dk
|
|
|
| |
|
|
| |
| |
| shilesh rastogi |
sir,
can u pls. send me the code for how to use rapi.dll in vb.net code. as i am facing problem. i have also to do the same thing copy a xml file from PPc to PC and vice versa.it will be very helpfull for me.
thanks in advance
shilesh rastogi
|
|
|
| |
|
| |
|
|
|
|
|
|