How to execute a file residing in memory with BoxedAPP - vb.net

I've purchased a license of BoxedAPP and when I wrote for help to the support mail I got any answer.
I've downloaded the SDK examples but all the important examples are in C# (and even if I use a translator I can't understand it), and the vb.net examples are for store files not executing they.
My question is simple, How I can use BoxedAPP to store a file in memory (Virtualize a file) and then execute it from memory?
For example I want to virtualize a Video file named "test.avi" as "my.resources.test" and then execute it with "process.start", this is what I've tryed to virtualize my recurse but don't run:
BoxedAppSDK.NativeMethods.BoxedAppSDK_CreateVirtualFile(My.Resources.test, _
BoxedAppSDK.NativeMethods.EFileAccess.GenericAll, _
BoxedAppSDK.NativeMethods.EFileShare.None, IntPtr.Zero, _
BoxedAppSDK.NativeMethods.ECreationDisposition.New, _
BoxedAppSDK.NativeMethods.EFileAttributes.Normal, _
IntPtr.Zero)

The first argument should be a string, check the function declaration:
<DllImport("bxsdk32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
Public Shared Function BoxedAppSDK_CreateVirtualFile( _
ByVal lpFileName As String, _
ByVal dwDesiredAccess As EFileAccess, _
ByVal dwShareMode As EFileShare, _
ByVal lpSecurityAttributes As IntPtr, _
ByVal dwCreationDisposition As ECreationDisposition, _
ByVal dwFlagsAndAttributes As EFileAttributes, _
ByVal hTemplateFile As IntPtr) As IntPtr
End Function
Also what does BoxedAppSDK_CreateVirtualFile return?

Related

Direct Disk Access: WinAPI WriteFile seems to fail on partitions larger than 2147483647 (7FFF FFFF) sectors

I wrote a small program in VB .Net to physically sort folder entries on FAT partitions (see http://www.public.bplaced.net). To do this, I use API calls to Kernel32.dll. I open the partition with CreateFileA, use the handle to lock the drive with DeviceIoControl FSCTL_LOCK_VOLUME and then read and write sectors directly with SetFilePointer / ReadFile / WriteFile (synchronous, with NO_BUFFERING).
All works PERFECTLY, except when I use my program with partitions larger than 2147483647 sectors (7FFF FFFF hex), WriteFile reports success but returns (and has) 0 byte written. This is the case no matter which sector I try to write. EVERYTHING else seems to still work as it should (including correct sector reading). When I use PartitionWizard to shrink the partition below the above limit, writing works again.
Question: does ANYBODY have a clue what could cause this strange behavior? My wild guess is that 'something' might interpret a value greater than 7FFF FFFF as 'signed'? Not within my code, the 'total sectors of partition' is not needed anywhere.
A friend also said that when he did something similar with 'streams', writing worked even with a 'large' partition...
I'm a total N00b, I can't even memorize all the terminology (but I still want to program so dearly...), so if you might have an explanation / hint / whatever, please describe it as simple-worded and detailled as possible.
Some code snippets (don't know where to start)... program is compiled for x86 systems. Problem occurs on both Win7 x86 and Win7 x64.
<DllImport("kernel32.dll", ExactSpelling:=True, SetLastError:=True, CharSet:=CharSet.Auto)> _
Public Shared Function DeviceIoControl _
( _
ByVal hDevice As IntPtr, _
ByVal dwIoControlCode As UInteger, _
ByVal lpInBuffer As IntPtr, _
ByVal nInBufferSize As UInteger, _
ByVal lpOutBuffer As IntPtr, _
ByVal nOutBufferSize As UInteger, _
ByRef lpBytesReturned As UInteger, _
ByVal lpOverlapped As IntPtr _
) _
As Integer
End Function
Public Declare Function CreateFile Lib "kernel32" _
Alias "CreateFileA" ( _
ByVal lpFileName As String, _
ByVal dwDesiredAccess As Int32, _
ByVal dwShareMode As Int32, _
ByVal lpSecurityAttributes As IntPtr, _
ByVal dwCreationDistribution As Int32, _
ByVal dwFlagsAndAttributes As Int32, _
ByVal hTemplateFile As Int32 _
) _
As IntPtr
Public Declare Function SetFilePointer Lib "kernel32" _
( _
ByVal hFile As IntPtr, _
ByVal lpDistanceToMove As UInt32, _
ByRef lpDistanceToMoveHigh As Int32, _
ByVal dwMoveMethod As UInt32 _
) _
As UInt32
Public Declare Function WriteFile Lib "kernel32" _
( _
ByVal hFile As IntPtr, _
ByVal lpBuffer As Byte(), _
ByVal nNumberOfBytesToWrite As Int32, _
ByRef lpNumberOfBytesWritten As Int32, _
ByVal lpOverlapped As IntPtr _
) _
As Boolean
' **********************************************************
' open the partition by drive letter
devicehandle = CreateFile( _
"\\.\" & driveletter & ":", _
GENERIC_READ Or GENERIC_WRITE, _
FILE_SHARE_READ Or FILE_SHARE_WRITE, _
IntPtr.Zero, _
OPEN_EXISTING, _
FILE_ATTRIBUTE_NORMAL Or FILE_FLAG_NO_BUFFERING, _
0 _
)
' **********************************************************
' lock the partition
Dim unused_lv As UInteger
Dim locked As Integer = DeviceIoControl( _
devicehandle, _
FSCTL_LOCK_VOLUME, _
IntPtr.Zero, _
0, _
IntPtr.Zero, _
0, _
unused_lv, _
IntPtr.Zero _
)
' **********************************************************
' set the file pointer, sector = sector to read, bytes_per_sector = 512. I use Bitconverter to get the hi and lo DWORDs
Dim s_bytes() As Byte = BitConverter.GetBytes(sector * bytes_per_sector)
' Hi-DWORD
Dim byte_dist_high As Int32 = BitConverter.ToInt32(s_bytes, 4) ' byte 4 - 7
' Lo-DWORD
Dim byte_dist_low As UInt32 = BitConverter.ToUInt32(s_bytes, 0) ' byte 0 - 3
' move file pointer
Dim move As UInt32 = SetFilePointer( _
devicehandle, _
byte_dist_low, _
byte_dist_high, _
FILE_BEGIN _
)
' **********************************************************
' write a sector
Dim write As Boolean = WriteFile( _
devicehandle, _
buffer, _
bytes_per_sector, _
bytes_written, _
IntPtr.Zero _
)
If write = False Then
Return False
Else
Return True
End If

vb.net win32api pointer to integer array parameter

Because I need to extract an icon from a file, but not the first icon, I cannot use the vb.net icon extraction function. The WIN32API function that should do this expects a pointer to an integer array.
How can I provide this type as a parameter?
Declare Function ExtractIconEx Lib "shell32.dll" Alias "ExtractIconExA" _
(ByVal lpszFile As String, _
ByVal nIconIndex As Integer, _
ByRef phiconLarge As Integer, _
ByRef phiconSmall As Integer, _
ByVal nIcons As Long) As Integer
Dim icons As integer()
ExtractIconEx("%systemroot%/shell32.dll", 15, icons, 0, 5)
I've taken a gander at the System.Reflection.Pointer class?/namespace?, but the documentation is sparse and less than sensible.
IntPtr doesn't provide support for arrays afaikt
Ok tx to Hans I've managed to correct the signature to:
<Runtime.InteropServices.DllImport("shell32.dll", _
CharSet:=Runtime.InteropServicesCharSet.Auto)> _
Shared Function ExtractIconEx(ByVal szFileName As String, _
ByVal nIconIndex As Integer, _
ByRef phiconLarge() As IntPtr, _
ByRef phiconSmall() As IntPtr, _
ByVal nIcons As UInteger) As UInteger
End Function
...
Dim icons(8) As IntPtr, smicons(8) As IntPtr
MsgBox(ExtractIconEx("%systemroot%/shell32.dll", 15, icons, smicons, 1))
Try
MsgBox(icons.Count)
Catch ex As Exception
MsgBox(ex.Message & " by " & ex.Source)
End Try
...
The subsequent calls always cause an exception (Value cannot be null). I get a return value of 4294967295, which is the maximum 32 bit integer value.
Any ideas how to tame this function and make it work?
ByRef phiconLarge() As IntPtr, _
ByRef phiconSmall() As IntPtr, _
The VB.NET declaration on that webpage has a bug, these arrays need to be passed ByVal, not ByRef. Note how they got it correct in the example code on the bottom of the page.
I edited the page to correct the bug.

Read/Write "INI" file

Evening Everyone -
I'm looking for some thoughts on how to read / write values from a windows "ini" structured file. I have a settings file created with another application and I would like to update values of a key within a specified section. I got it working using a buffer.replace process but now realize that some keys are used over in sections and globally replacing a value will cause problems.
Here is a sample of what my ini file looks like
IMPORT-1]
SETTINGS="HELLO"
FILENAME="C:\TEST\TEST1.CSV"
[ENCODE-2]
FILENAME="C:\TEST\REPORT1.XPS"
I've got dozens of blocks so any clarity on accomplishing a read and write of a value within a specific section would be hugely appreciated!
--Cheers & Thanks
George
You can use some of the kernel32 functions.
Private Declare Auto Function GetPrivateProfileString Lib "kernel32" (ByVal lpAppName As String, _
ByVal lpKeyName As String, _
ByVal lpDefault As String, _
ByVal lpReturnedString As StringBuilder, _
ByVal nSize As Integer, _
ByVal lpFileName As String) As Integer
This will let you read an ini file
Dim sb As StringBuilder
sb = New StringBuilder(500)
GetPrivateProfileString("IMPORT-1", "SETTINGS", "", sb, sb.Capacity, "test.ini")

Windows printer spooler setjob function not working for Windows-7?

I am updating our "Printer Monitoring" application. Previously this application runs successfully on Windows 2000 server. Now we shifted to Windows 7 server. On windows 7 our "Print monitor" application crashes. When I debug it, I found that our SetJob function throws the following exception:
The parameter is incorrect.
Does anyone know anything about this?
Function call:
SetJob(
mhPrinter,
midJob,
0,
IntPtr.Zero,
PrintJobControlCommands.JOB_CONTROL_PAUSE) 'Here exception is thrown
Spooler API which we use :
<DllImport("winspool.drv", EntryPoint:="SetJob", _
SetLastError:=True, CharSet:=CharSet.Ansi, _
ExactSpelling:=False, _
CallingConvention:=CallingConvention.StdCall)> _
Public Function SetJob _
(<InAttribute()> ByVal hPrinter As IntPtr, _
<InAttribute()> ByVal dwJobId As Int32, _
<InAttribute()> ByVal Level As Int32, _
<InAttribute()> ByVal lpJob As IntPtr, _
<InAttribute(), MarshalAs(UnmanagedType.U4)> ByVal dwCommand As PrintJobControlCommands _
) As Boolean
Please have a loop here, how the function has to be build and how the parsmeters are called:
http://www.pinvoke.net/default.aspx/winspool.setjob
It is a bit different then you implemented it. Hope it will help.

Can I Call unmanaged Mobile CE Dll from Full .Net Framework (Run on Desktop)

I have an Unmanaged Lib compiled for Windows Ce. I am trying to call this dll from VB.net Full Framework .Net 4 Client Profile Windows application. I am trying to use the same code that I use in the Compact Framework application. It compiles without errors and runs but when Invoking a function I get error ex = {"An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)"} Is it possible to use the Mobile Unmanaged Dll on the Desktop ? Here is the Wrapper code I use to call the Dll:
Imports System
Imports System.Runtime.InteropServices
Module modM300CF
Public Declare Function ParseBarCode Lib "M300LAP.dll" ( _
ByVal P_track1 As Byte(), ByVal P_t1length As Short, _
ByRef P_DLStatus As Short, _
ByRef P_StateID As Byte, _
ByRef P_DAge As Short, _
ByRef P_CardName As Byte, _
ByRef P_Address As Byte, _
ByRef P_City As Byte, _
ByRef P_State As Byte, _
ByRef P_Zip As Byte, _
ByRef P_DLNumber As Byte, _
ByRef P_Expdate As Byte, _
ByRef P_Bdate As Byte, _
ByRef P_DLAlpha As Byte, _
ByRef P_DHair As Byte, _
ByRef P_DEyes As Byte, _
ByRef P_DHeight As Byte, _
ByRef P_DWeight As Byte, _
ByRef P_DSex As Byte) As Short
Public Declare Function ParseMagStripe Lib "M300LAP.dll" ( _
ByVal P_track1 As Byte(), ByVal P_t1length As Short, _
ByVal P_track2 As Byte(), ByVal P_t2length As Short, _
ByVal P_track3 As Byte(), ByVal P_t3length As Short, _
ByRef P_DLStatus As Short, _
ByRef P_StateID As Byte, _
ByRef P_DAge As Short, _
ByRef P_CardName As Byte, _
ByRef P_Address As Byte, _
ByRef P_City As Byte, _
ByRef P_State As Byte, _
ByRef P_Zip As Byte, _
ByRef P_DLNumber As Byte, _
ByRef P_Expdate As Byte, _
ByRef P_Bdate As Byte, _
ByRef P_DLAlpha As Byte, _
ByRef P_DHair As Byte, _
ByRef P_DEyes As Byte, _
ByRef P_DHeight As Byte, _
ByRef P_DWeight As Byte, _
ByRef P_DSex As Byte) As Short
End Module
I could be wrong but I believe the binary format is slightly different on Windows CE which might explain why desktop windows is having difficulty making sense of the image file