[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

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

Posted on 2004-09-08
40
Medium Priority
?
1,533 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 21
  • 18
40 Comments
 

Author Comment

by:rahjinoh
ID: 12007798
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
ID: 12007998
you would need a way to interpret the beam signals from the IR port
0
Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

 

Author Comment

by:rahjinoh
ID: 12265578
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
ID: 12464922
does he still want an answer?
0
 

Author Comment

by:rahjinoh
ID: 12469033
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
ID: 12469379
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
ID: 12470504
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
ID: 12472540
you have to use DllImport to make the API work
0
 

Author Comment

by:rahjinoh
ID: 12473307
<DllImport("CORE.DLL")>  ?

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

Expert Comment

by:Mikal613
ID: 12473360
<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
ID: 12473414
'System.Runtime.Interopservices.DllimportAttribute' cannot be applied to a 'Declare'
0
 
LVL 48

Expert Comment

by:Mikal613
ID: 12473423
try public shared instead of Public declare
0
 

Author Comment

by:rahjinoh
ID: 12473631
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
ID: 12473861
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
ID: 12473917
i still get the End of Statement Expected error though
0
 

Author Comment

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

Expert Comment

by:Mikal613
ID: 12474063
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
 

Author Comment

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

Expert Comment

by:Mikal613
ID: 12474128
what line is the error?
0
 

Author Comment

by:rahjinoh
ID: 12474223
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
ID: 12474272
http://www.devx.com/wireless/Article/21291

check out the code whats different?
0
 
LVL 48

Expert Comment

by:Mikal613
ID: 12474280
can you post all your code?
0
 

Author Comment

by:rahjinoh
ID: 12474461
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
ID: 12475508
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 1120 total points
ID: 12475687
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
ID: 12475693
0
 
LVL 48

Expert Comment

by:Mikal613
ID: 12475779
0
 

Author Comment

by:rahjinoh
ID: 12476656
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
ID: 12476705
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
ID: 12477019
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
ID: 12477041
well where did you put the function dont put it in your startup function

Try debugging it
0
 

Author Comment

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

Expert Comment

by:Mikal613
ID: 12607412
Can you please send me your final code

Thanks a Ton!!!!
0
 

Author Comment

by:rahjinoh
ID: 12610488
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
ID: 12610507
you didnt use shellexecute?
0
 

Author Comment

by:rahjinoh
ID: 12610662
there's no ShellExecute in .NET CF
0
 
LVL 48

Expert Comment

by:Mikal613
ID: 12610681
there actually is 11 posts above , it works also

Thanks for posting

;)
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Progress means simplifying, not complicating. Bruno Munari Preface How to detect the name of the internal storage or an SD-card on Windows Mobile device from the desktop application? I got this question, when I was working on a PC applicati…
I recently asked a question (http://www.experts-exchange.com/Programming/Smartphones/Android/Q_28684946.html) about Computer Inventory applications for Mobile Devices.  I was specifically interested in an app I could use on my android phone.  The be…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

649 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