Link to home
Start Free TrialLog in
Avatar of rahjinoh
rahjinoh

asked on

File Sending with IrDA (PPC to Others) with VB.NET

I am currenting using "OBEX" as the servicename to send a image from a PPC to Any other device, e.g PC thru IrDA.

Current my code allows me to send the file, but it doesn't appear anywhere in my PC. (It only appears to send, not sure if it really did.)

Also, while sometimes it's ok to send 1 file, it crashes when i try to send another.

Error given was

"An unhandled exception of type 'System.IO.IOException' occurred in System.dll, Additional information: Unable to write data to the transport connection."

My IrDA Data transfer code is as followed...

Private Function ir_senddata() As Boolean
    Dim irClient As New IrDAClient
    Dim irServiceName As String = "OBEX"
    Dim buffersize As Integer = 65535

    Dim fs As Stream
    Try
      fs = New FileStream("\TEST.JPG", FileMode.Open)
    Catch exFile As Exception
      global.prompt(global.errorcode(5) & exFile.ToString) : Return False
    End Try

    Try
      irClient = New IrDAClient(irServiceName)
    Catch exS As SocketException
      global.prompt(global.errorcode(6) & exS.Message) : Return False
    End Try

    Dim baseStream As Stream = irClient.GetStream()
    Dim length As Byte() = BitConverter.GetBytes(Fix(fs.Length))
    baseStream.Write(length, 0, length.Length)

    Dim buffer(buffersize) As Byte
    Dim fileLength As Integer = CInt(fs.Length)

    While fileLength > 0
      Dim numRead As Integer = fs.Read(buffer, 0, buffer.Length)
      baseStream.Write(buffer, 0, numRead)
      fileLength -= numRead
    End While

    fs.Close()
    baseStream.Close()
    irClient.Close()
  End Function


Can anyone divert me to a really good example code of file/data sending with IrDA from PPC in VB.NET? And what caused the error? (And, any Bluetooth codes as well?:))

Thanks!
Avatar of Mikal613
Mikal613
Flag of United States of America image

Avatar of rahjinoh
rahjinoh

ASKER

If you noticed, that's the code i based on in my function, i want to send it to my notebook thru IrDA, however, i would like to "just" send it, without having to have a "Server Listener" to wait for a IrDA connection to receive the file.

I would like to just send it, and Windows can pick up the file directly.

The sample from gotdotnet provides codes for a Sender & Receiver. My code is based on the Sender. But is there a way to send my file to another device without a "server"?
you would need a way to interpret the beam signals from the IR port
Well, after so long but several unsuccessful attempts, here's to savage the situation :)

Is there anyway to call up the BEAM FILES form that appears when you tap and hold a file and select BEAM FILE in File Explorer in WM2003?

If there's a way to call up that and allow me to send file thru that, everything would be ok.

Anyone? :)
does he still want an answer?
If you have an answer for me, feel free to say it, coz i've sort of neglected that project due to this problem, haven't been able to solve it.

Question, in Resco Explorer, or File Explorer, you can tap SEND TO -> INFRARED to send files.
How do you call up that exact form to send files thru that?

Any ideas?
Option Explicit
Public Declare Function CreateProcess Lib "coredll" Alias "CreateProcessW" ( _
    ByVal pszImageName As String, _
    ByVal pszCmdLine As String, _
    ByVal psaProcess As Long, _
    ByVal psaThread As Long, _
    ByVal fInheritHandles As Long, _
    ByVal fdwCreate As Long, _
    ByVal pvEnvironment As Long, _
    ByVal pszCurDir As Long, _
    ByVal psiStartInfo As Long, _
    ByVal pProcInfo As Long) As Long

Private Sub Command1_Click()
    Dim lnCreateProcess As Long
    Dim strFileName As String
    strFileName = "\My Documents\DocName.psw" <---- The File you wanna beam
    On Error Resume Next
    lnCreateProcess = CreateProcess("\Windows\Beam.exe", strFileName, 0, 0, 0, 0, 0, 0, 0, 0)
    If lnCreateProcess = 0 Then
        MsgBox Err.Description
    End If
End Sub
I've got a NotSupportedException. Any ideas?
If it would help, i'm using a XDAII

Thanks for your patience :)
you have to use DllImport to make the API work
<DllImport("CORE.DLL")>  ?

Any hints? i'm really dumb at marshalling. Which unmanaged dll should i import?
<DllImport("coredll")> _

    Public Declare Function CreateProcess Lib "coredll" Alias "CreateProcessW" ( _
    ByVal pszImageName As String, _
    ByVal pszCmdLine As String, _
    ByVal psaProcess As Long, _
    ByVal psaThread As Long, _
    ByVal fInheritHandles As Long, _
    ByVal fdwCreate As Long, _
    ByVal pvEnvironment As Long, _
    ByVal pszCurDir As Long, _
    ByVal psiStartInfo As Long, _
    ByVal pProcInfo As Long) As Long

'System.Runtime.Interopservices.DllimportAttribute' cannot be applied to a 'Declare'
try public shared instead of Public declare
I tried that before too, there's a End Of Statement Expected Error, but i dun understand why.
Imports System.Runtime.InteropServices

    Imports System.Text

 
the import should be global
 

        <DllImport("coredll")> _

                Public Shared Function CreateProcess Lib "coredll" Alias "CreateProcessW" ( _
    ByVal pszImageName As String, _
    ByVal pszCmdLine As String, _
    ByVal psaProcess As Long, _
    ByVal psaThread As Long, _
    ByVal fInheritHandles As Long, _
    ByVal fdwCreate As Long, _
    ByVal pvEnvironment As Long, _
    ByVal pszCurDir As Long, _
    ByVal psiStartInfo As Long, _
    ByVal pProcInfo As Long) As Long
i still get the End of Statement Expected error though
Adding a "End Function" didn't help too
Public Shared Function CreateProcess Lib "coredll" Alias "CreateProcessW" ( _
    ByVal pszImageName As String, _
    ByVal pszCmdLine As String, _
    ByVal psaProcess As Long, _
    ByVal psaThread As Long, _
    ByVal fInheritHandles As Long, _
    ByVal fdwCreate As Long, _
    ByVal pvEnvironment As Long, _
    ByVal pszCurDir As Long, _
    ByVal psiStartInfo As Long, _
    ByVal pProcInfo As Long) As Long

END FUNCTION <------ thats the problem
As i mentioned above, adding the "End Function" didn't help too :)
what line is the error?
the blue wavy error underline started from

Lib "coredll".... all the way to ....ByVal pProcInfo As Long)As Long

with an Error : End Of Statement Expected
http://www.devx.com/wireless/Article/21291

check out the code whats different?
can you post all your code?
Removing Lib "coredll" Alias "CreateProcessW" removes the error, but still gives NotSupportedException in my PPC.

i created a new form with a btn and used your code with the Command1_Click on top. On change made was the Path and File name which is now "\Storage Card\image.jpg"
From what i can tell, the code actually emulates a "Shell" function that doesn't exists in CF .NET.
But i can't get it to work.
ASKER CERTIFIED SOLUTION
Avatar of Mikal613
Mikal613
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
The code didn't really work... not out of the box at least.
But after serveral modifications, and editing, i finally managed to get the beam.exe to send files!

Thank you so much for your time and patience :)

Really appreciate that. Thx, i upped the points for you :)
Ohhh  thanks alot

Woo hoo we did it!!

And I just took a guess that the Beam would have a parameter
that's a great guess, hehe, heck i didn't even realised there's a Beam.exe in the Windows folder, seems like i better explore the Windows folder more.

I had thought the beaming of files was done thu a API Call to explorer.exe

Oh, and there's just a little tinny question, After i create that  new process to beam files, my original app killed itself. Any idea why and how do i stop that? :)
well where did you put the function dont put it in your startup function

Try debugging it
it wasn't a startup, anyway, i managed to stop it, abeit a lame way :D
hehe
Can you please send me your final code

Thanks a Ton!!!!
Imports System.Runtime.InteropServices

Public Class Wireless
  <DllImport("CoreDll.DLL", SetLastError:=True)> _
  Private Shared Function CreateProcess(ByVal imageName As String, ByVal cmdLine As String, ByVal lpProcessAttributes As IntPtr, ByVal lpThreadAttributes As IntPtr, ByVal boolInheritHandles As Int32, ByVal dwCreationFlags As Int32, ByVal lpEnvironment As IntPtr, ByVal lpszCurrentDir As IntPtr, ByVal si() As Byte, ByVal pi As ProcessInfo) As Integer
  End Function

  <DllImport("CoreDll.dll")> _
  Private Shared Function GetLastError() As Int32
  End Function

  Public Shared Function CreateProc(ByVal ExeName As String, ByVal CmdLine As String, ByVal pi As ProcessInfo) As Boolean
    If pi Is Nothing Then
      pi = New ProcessInfo
    End If
    Dim si(127) As Byte
    Return CreateProcess(ExeName, CmdLine, IntPtr.Zero, IntPtr.Zero, 0, 0, IntPtr.Zero, IntPtr.Zero, si, pi) <> 0
  End Function 'CreateProc
End Class 'Externals

Public Class ProcessInfo
  Public hProcess As IntPtr
  Public hThread As IntPtr
  Public ProcessId As Int32
  Public ThreadId As Int32
End Class 'ProcessInfo

Wireless.CreateProc("\Windows\Beam.exe", filename, nothing)
you didnt use shellexecute?
there's no ShellExecute in .NET CF
there actually is 11 posts above , it works also

Thanks for posting

;)