Solved

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

Posted on 2004-09-08
40
1,522 Views
Last Modified: 2013-11-18
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!
0
Comment
Question by:rahjinoh
  • 21
  • 18
40 Comments
 
LVL 48

Expert Comment

by:Mikal613
Comment Utility
0
 

Author Comment

by:rahjinoh
Comment Utility
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"?
0
 
LVL 48

Expert Comment

by:Mikal613
Comment Utility
you would need a way to interpret the beam signals from the IR port
0
 
LVL 48

Expert Comment

by:Mikal613
Comment Utility
0
 

Author Comment

by:rahjinoh
Comment Utility
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? :)
0
 
LVL 48

Expert Comment

by:Mikal613
Comment Utility
does he still want an answer?
0
 

Author Comment

by:rahjinoh
Comment Utility
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?
0
 
LVL 48

Expert Comment

by:Mikal613
Comment Utility
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
0
 

Author Comment

by:rahjinoh
Comment Utility
I've got a NotSupportedException. Any ideas?
If it would help, i'm using a XDAII

Thanks for your patience :)
0
 
LVL 48

Expert Comment

by:Mikal613
Comment Utility
you have to use DllImport to make the API work
0
 

Author Comment

by:rahjinoh
Comment Utility
<DllImport("CORE.DLL")>  ?

Any hints? i'm really dumb at marshalling. Which unmanaged dll should i import?
0
 
LVL 48

Expert Comment

by:Mikal613
Comment Utility
<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

0
 

Author Comment

by:rahjinoh
Comment Utility
'System.Runtime.Interopservices.DllimportAttribute' cannot be applied to a 'Declare'
0
 
LVL 48

Expert Comment

by:Mikal613
Comment Utility
try public shared instead of Public declare
0
 

Author Comment

by:rahjinoh
Comment Utility
I tried that before too, there's a End Of Statement Expected Error, but i dun understand why.
0
 
LVL 48

Expert Comment

by:Mikal613
Comment Utility
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
0
 

Author Comment

by:rahjinoh
Comment Utility
i still get the End of Statement Expected error though
0
 

Author Comment

by:rahjinoh
Comment Utility
Adding a "End Function" didn't help too
0
 
LVL 48

Expert Comment

by:Mikal613
Comment Utility
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
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:rahjinoh
Comment Utility
As i mentioned above, adding the "End Function" didn't help too :)
0
 
LVL 48

Expert Comment

by:Mikal613
Comment Utility
what line is the error?
0
 

Author Comment

by:rahjinoh
Comment Utility
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
0
 
LVL 48

Expert Comment

by:Mikal613
Comment Utility
http://www.devx.com/wireless/Article/21291

check out the code whats different?
0
 
LVL 48

Expert Comment

by:Mikal613
Comment Utility
can you post all your code?
0
 

Author Comment

by:rahjinoh
Comment Utility
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"
0
 

Author Comment

by:rahjinoh
Comment Utility
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.
0
 
LVL 48

Accepted Solution

by:
Mikal613 earned 280 total points
Comment Utility
Imports System.Runtime.InteropServices
Imports System.Text



Class SHELLEXECUTEEX
   Public cbSize As UInt32
   Public fMask As UInt32
   Public hwnd As IntPtr
   Public lpVerb As IntPtr
   Public lpFile As IntPtr
   Public lpParameters As IntPtr
   Public lpDirectory As IntPtr

   Public nShow As Integer
   Public hInstApp As IntPtr
   ' Optional members
   Public lpIDList As IntPtr
   Public lpClass As IntPtr
   Public hkeyClass As IntPtr
   Public dwHotKey As UInt32
   Public hIcon As IntPtr
   Public hProcess As IntPtr
End Class 'SHELLEXECUTEEX

<DllImport("coredll")>  _
Private Shared Function ShellExecuteEx(ex As SHELLEXECUTEEX) As Integer

<DllImport("coredll")>  _
Private Shared Function LocalAlloc(flags As Integer, size As Integer) As
IntPtr

<DllImport("coredll")>  _
Private Shared Sub LocalFree(ptr As IntPtr)

' Code starts here
Dim docname As String = "\windows\default.htm"
Dim nSize As Integer = docname.Length * 2 + 2
Dim pData As IntPtr = LocalAlloc(&H40, nSize)
Marshal.Copy(Encoding.Unicode.GetBytes(docname),0,pData,nSize - 2)

   Dim see As New SHELLEXECUTEEX()
   see.cbSize = 60
   see.dwHotKey = 0
   see.fMask = 0
   see.hIcon = IntPtr.Zero
   see.hInstApp = IntPtr.Zero
   see.hProcess = IntPtr.Zero
   see.lpClass = IntPtr.Zero
   see.lpDirectory = IntPtr.Zero
   see.lpIDList = IntPtr.Zero
   see.lpParameters = Pathto Fileto beam
   see.lpVerb = IntPtr.Zero
   see.nShow = 0
   see.lpFile = pData

   ShellExecuteEx(see)

   LocalFree(pData)
0
 
LVL 48

Expert Comment

by:Mikal613
Comment Utility
0
 
LVL 48

Expert Comment

by:Mikal613
Comment Utility
0
 

Author Comment

by:rahjinoh
Comment Utility
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 :)
0
 
LVL 48

Expert Comment

by:Mikal613
Comment Utility
Ohhh  thanks alot

Woo hoo we did it!!

And I just took a guess that the Beam would have a parameter
0
 

Author Comment

by:rahjinoh
Comment Utility
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? :)
0
 
LVL 48

Expert Comment

by:Mikal613
Comment Utility
well where did you put the function dont put it in your startup function

Try debugging it
0
 

Author Comment

by:rahjinoh
Comment Utility
it wasn't a startup, anyway, i managed to stop it, abeit a lame way :D
hehe
0
 
LVL 48

Expert Comment

by:Mikal613
Comment Utility
Can you please send me your final code

Thanks a Ton!!!!
0
 

Author Comment

by:rahjinoh
Comment Utility
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)
0
 
LVL 48

Expert Comment

by:Mikal613
Comment Utility
you didnt use shellexecute?
0
 

Author Comment

by:rahjinoh
Comment Utility
there's no ShellExecute in .NET CF
0
 
LVL 48

Expert Comment

by:Mikal613
Comment Utility
there actually is 11 posts above , it works also

Thanks for posting

;)
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

I think the most popular question in our Windows Mobile Programming zone is about the backlight - we all want to keep it on when our application is running. Few years ago the function SystemIdleTimerReset() did this job. On our side we had to detec…
This article shows how to setup the internet connectivity on Windows Mobile Emulator.   I assume that you already have Microsoft Visual Studio, Microsoft Windows Mobile SDK's and the emulator installed. The emulator is available with Visual Studi…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now