Solved

Unable to create shortcut with VB6 on an iPAQ using ActiveSync CeSHCreateShortcut api call

Posted on 2006-11-30
15
396 Views
Last Modified: 2012-08-14
I've written an app that copies some files to an iPAQ. I just need to create a shortcut on the iPAQ that points to the executable I've installed. The rapi.dll that's part of ActiveSync includes a function called CeSHCreateShortcut. Microsoft's description: "This function creates a new shortcut on a remote Windows Embedded CE–based device." Just what I want to do. From the object browser:

Function CeSHCreateShortcut(lpszShortcut As String, lpszTarget As String) As Long
    Member of RemoteCETypeLibrary.CERAPI
    The CeSHCreateShortcut function creates a shortcut.

So I've got this declaration:

Public Declare Function CeSHCreateShortcut& Lib "rapi.dll" ( lpShortcut$, lpTarget$)

Used in this function:

Public Function RapiCreateShortcut(sShortcut$, sTarget$) As Boolean
  Dim lResult&
  lResult& = CeSHCreateShortcut(sShortcut$, sTarget$)
  RapiCreateShortcut = (lResult& <> 0)
End Function

And I call it something like this:

RapiCreateShortcut "ShortcutName", "\Program Files\Unichip\Flux\Application.exe"

It says it's successful, but I get a file with unprintable characters in its name in root of the PDA. It's not a valid shortcut.

Could someone please point out where I'm going wrong? Thanks.


0
Comment
Question by:ketchukf
[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
  • 8
  • 7
15 Comments
 
LVL 29

Expert Comment

by:nffvrxqgrcfqvvc
ID: 18051267
Whenever your passing a string in an API decleration you always pass the string Byval, in your decleration your passing it Byref, I also looked at the microsoft documentation and that function is asking for a string pointer so what you are seeing is most likely unicode characters.

From microsoft :

This function creates a shortcut. CeSHCreateShortcut is a remote application interface (RAPI), which enables an application running on a desktop computer to make function calls on a Windows CE–based device.


BOOL CeSHCreateShortcut(
LPWSTR lpszShortcut,
LPWSTR lpszTarget);


Although I can't test this myself you can try the following


Option Explicit

Private Declare Function CeSHCreateShortcut Lib "rapi.dll" ( _
    ByVal lpszShortcut As Long, _
    ByVal lpszTarget As Long) As Boolean

Public Function CreateShortcuts( _
    ByVal Shortcutname As String, _
    ByVal ShortCutTarget As String) As Boolean
   
        CreateShortcuts = CeSHCreateShortcut( _
            StrPtr(Shortcutname), _
            StrPtr(ShortCutTarget))
       
End Function


0
 

Author Comment

by:ketchukf
ID: 18053134
Thanks for the comment. I think what you're saying is usually true, but not in this case. From AllAPI.net:

Some types begin with LP. It is an abbreviation of Long Pointer to. So LPWORD is actually a memory location where the data is stored. No, you won't have to call a function to get this address. When you pass your argument ByRef (the default) you actually pass its address. The thing to remember here is that, if you parameter type begins with LP - you should pass it ByRef.

0
 
LVL 29

Expert Comment

by:nffvrxqgrcfqvvc
ID: 18053685
hi, ketchukf,

The conversion I posted should be correct in Visual Basic 6 and if I am wrong pherhaps another expert could point this out.


So I take it what I have posted is not working correctly for you? Are you getting any type of errors?
0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 

Author Comment

by:ketchukf
ID: 18055116
I tried ByVal and I think CeGetLastError returned 'Invalid function call' or something like that. I'll try it again this evening and post the exact error.
0
 

Author Comment

by:ketchukf
ID: 18057982
eql1044,

I had a chance to test your code and CeSHCreateShortcut returns success, like it does with the code in my original question, but I don't have a shortcut. I've passed CeSHCreateShortcut  the name of the shortcut I want to create, the path and the name, the path and the name with a .lnk extension, and the result is always the same. No shortcut. Not that I can find, anyway.

I've been working with computers for a long time. I'll feel funny calling Microsoft and asking for help creating a shortcut.
0
 
LVL 29

Expert Comment

by:nffvrxqgrcfqvvc
ID: 18058162
Could you post how you are specifying the Shortcut and Target that you are using in regards to using the function I provided.

0
 
LVL 29

Accepted Solution

by:
nffvrxqgrcfqvvc earned 250 total points
ID: 18058220
What about something like this? I dont know how your device works exactly but I do know that on some devices you might need to power off the device or restart the device so the changes go into effect.

Option Explicit

Private Declare Function CeSHCreateShortcut Lib "rapi.dll" ( _
    ByVal lpszShortcut As Long, _
    ByVal lpszTarget As Long) As Boolean

Public Function CreateShortcuts( _
    ByVal ShortcutName As String, _
    ByVal ShortcutTarget As String) As Boolean
   
        CreateShortcuts = CeSHCreateShortcut( _
            StrPtr(ShortcutName), _
            StrPtr(ShortcutTarget))
       
End Function

Private Sub Form_Load()
Debug.Print CreateShortcuts("\windows\desktop\Name.lnk", """\Program Files\Folder\Name.exe\""")
End Sub
0
 

Author Comment

by:ketchukf
ID: 18058448
If Not CreateShortcuts("Company Gadget", "\Program Files\Company\Gadget\Company Gadget.exe") Then ...

Like I said earlier, I've tried path and shortcut name, path and name and .lnk extension, same thing.

The files that I copy to the PDA show up as they're being copied. I can refresh the directory listing and see the size of the biggest file increase as it's being copied. I'm sure the shortcut would appear if it were there.
0
 
LVL 29

Expert Comment

by:nffvrxqgrcfqvvc
ID: 18061219
Have you tried with the double quotes?
0
 

Author Comment

by:ketchukf
ID: 18061273
Yes. Same result. CeSHCreateShortcut returns 0, but no shortcut. I tried deleting a shortcut to some other application and recreating it. Same result.
0
 

Author Comment

by:ketchukf
ID: 18090217
eql1044, thanks for your time and effort trying to help me with this problem.

Here's the answer I received on Usenet. It worked like a charm.

When you declare a function like this, VB does some work behind the
scenes to make it work. It converts the string as it's stored internally
to a null terminated ASCII string and passes it to the function (and
does the reverse conversion afterwards).

This normally works because you can call into the ASCII version of any
random Windows API. The RAPI functions, however, don't have an ASCII
version and expect Unicode strings. Here's an example of how you can do
this:

Option Explicit

' Using As Any declarations to avoid VB's string handling
Public Declare Function CeSHCreateShortcut Lib "rapi.dll" _
    (lpShortcut As Any, lpTarget As Any) As Long
Public Declare Function CeRapiInit Lib "rapi.dll" () As Long
Public Declare Function CeRapiUninit Lib "rapi.dll" () As Long

Public Function RapiCreateShortcut(sShortcut As String, _
    sTarget As String) As Boolean

    Dim lResult As Long
    Dim bShortcut() As Byte
    Dim bTarget() As Byte

    ' Use the byte array to get a Unicode version of
    '  the strings, ensuring a null character on the end
    bShortcut = sShortcut & vbNullChar
    bTarget = sTarget & vbNullChar

    lResult = CeSHCreateShortcut(bShortcut(0), bTarget(0))

    RapiCreateShortcut = (lResult <> 0)

End Function

Sub Example()
    CeRapiInit

    ' Note:  Quotes appear needed for the target name
    '  if there are embedded spaces.
    RapiCreateShortcut "\ShortcutName.lnk", _
        """\Program Files\Application.exe"""

    CeRapiInit
End Sub

--
Scott Seligman [MSFT]
This posting is provided AS IS with no warranties, and confers
no rights.
0
 
LVL 29

Expert Comment

by:nffvrxqgrcfqvvc
ID: 18095621
Great to hear its working, Have you by any chance tested my code with the proper formatting?
Adding Vbnullchar to the end? I still belive what I have posted is correct.

"\ShortcutName.lnk", _
        """\Program Files\Application.exe"""
0
 

Author Comment

by:ketchukf
ID: 18099067
Yes egl1044, I believe I tested every suggestion you offered. I tried appending vbNullChar to each string before I posted on EE, without any luck.
0
 
LVL 29

Expert Comment

by:nffvrxqgrcfqvvc
ID: 18099073
I will have to admit, I left you on the wrong path and I must be wrong. Good luck
0
 

Author Comment

by:ketchukf
ID: 18110864
egl1044, I must have missed something because your earlier suggestion is essentially what I'm using now, and it works. I don't know if I had a typo or what.

Thanks for your help.
0

Featured Post

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SLMGR Switches Are Not Working On KMS Host 3 170
Automatic Email Reminder 4 94
VB script to continue despite error 2 78
VBA Replace Function - What am I missing? 3 52
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

752 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