Using SHAddToRecentDocs to populate Documents menu 
Author Message
 Using SHAddToRecentDocs to populate Documents menu

Hi everyone,

I'm trying to use the API function "SHAddToRecentDocs" in "Shell32.dll" to
add items to the "Start | Documents" menu.  Below are the declarations and
call:

     Declare Function SHAddToRecentDocs Lib "Shell32" (ByVal uFlags As Long,
ByVal pv As String)
     Private Const SHARD_PATHA As Long = 2         ' also tried &H2

     Call SHAddToRecentDocs(SHARD_PATHA, pth)

The above call generates a "Bad DLL calling convention" error, which usually
means there's a conflict involving the arguments in the declaration, the
call, and/or the API routine itself.  I should mention that the declaration
wasn't in the API Text Viewer, so I'm not sure if the declaration is
*exactly* correct; however, I did a test in Visual C++, and had no problem
calling the routine, so I think I understand the arguments.  I've tried
changing the declaration around as many ways as I can think: ByVal vs.
ByRef, Integer vs. Long, etc., but no luck.  By the way, the "pth" argument
is fine -- I pass it to the API function "GetShortPathName" a few lines
above and have no problems.

Any ideas?

TIA,

Mike



Sat, 30 Dec 2000 03:00:00 GMT  
 Using SHAddToRecentDocs to populate Documents menu

Mike

Quote:
> I'm trying to use the API function "SHAddToRecentDocs" in "Shell32.dll" to
> add items to the "Start | Documents" menu.  Below are the declarations and
> call:

>      Declare Function SHAddToRecentDocs Lib "Shell32" (ByVal uFlags As Long,
> ByVal pv As String)
>      Private Const SHARD_PATHA As Long = 2         ' also tried &H2

>      Call SHAddToRecentDocs(SHARD_PATHA, pth)

> The above call generates a "Bad DLL calling convention" error

Uh... just one. SHAddToRecentDocs is a Sub, not a Function. It
returns a "void". Otherwise everything else looks good.

--
Brad Martinez
http://members.aol.com/btmtz/vb
http://www.mvps.org/ccrp

Please direct questions/replies to the newsgroup.



Sat, 30 Dec 2000 03:00:00 GMT  
 Using SHAddToRecentDocs to populate Documents menu
Hi,

Declare the "function" as sub or add a long as the type of returning type:

Declare Function SHAddToRecentDocs Lib "Shell32" (ByVal uFlags As Long,
ByVal pv As String) As Long

Declare Sub SHAddToRecentDocs Lib "Shell32" (ByVal uFlags As Long, ByVal pv
As String)

Saludos.
guillermo
--
==================================================
Te invito a visitar mis pginas sobre Visual Basic
http://guille.costasol.net/
==================================================

Mike Dyer escribi en mensaje

Quote:
>Hi everyone,

>I'm trying to use the API function "SHAddToRecentDocs" in "Shell32.dll" to
>add items to the "Start | Documents" menu.  Below are the declarations and
>call:

>     Declare Function SHAddToRecentDocs Lib "Shell32" (ByVal uFlags As
Long,
>ByVal pv As String)
>     Private Const SHARD_PATHA As Long = 2         ' also tried &H2

>     Call SHAddToRecentDocs(SHARD_PATHA, pth)

>The above call generates a "Bad DLL calling convention" error, which
usually
>means there's a conflict involving the arguments in the declaration, the
>call, and/or the API routine itself.  I should mention that the declaration
>wasn't in the API Text Viewer, so I'm not sure if the declaration is
>*exactly* correct; however, I did a test in Visual C++, and had no problem
>calling the routine, so I think I understand the arguments.  I've tried
>changing the declaration around as many ways as I can think: ByVal vs.
>ByRef, Integer vs. Long, etc., but no luck.  By the way, the "pth" argument
>is fine -- I pass it to the API function "GetShortPathName" a few lines
>above and have no problems.

>Any ideas?

>TIA,

>Mike



Sun, 31 Dec 2000 03:00:00 GMT  
 Using SHAddToRecentDocs to populate Documents menu
If you are going to declare it as a function, which I have done on the
SHAddToRecentDocs example on my site, you *must* define the return value of
the declare.  In your example, you omitted the "As Long" from the end of the
declare.  VB casts it to a variant, guaranteed to bring an API to its knees.
I guaranteed this is the problem.

FWIW, I've used this declare:

Public Declare Function SHAddToRecentDocs Lib "shell32.dll" _
  (ByVal dwFlags As Long, ByVal dwData As String) As Long

--

Randy Birch, MVP Visual Basic

VBnet, The Visual Basic Developers Resource Centre
http://www.mvps.org/vbnet

Common Controls Replacement Project Member
http://www.mvps.org/ccrp


:Hi everyone,
:
:I'm trying to use the API function "SHAddToRecentDocs" in "Shell32.dll" to
:add items to the "Start | Documents" menu.  Below are the declarations and
:call:
:
:     Declare Function SHAddToRecentDocs Lib "Shell32" (ByVal uFlags As
Long,
:ByVal pv As String)
:     Private Const SHARD_PATHA As Long = 2         ' also tried &H2
:
:     Call SHAddToRecentDocs(SHARD_PATHA, pth)
:
:The above call generates a "Bad DLL calling convention" error, which
usually
:means there's a conflict involving the arguments in the declaration, the
:call, and/or the API routine itself.  I should mention that the declaration
:wasn't in the API Text Viewer, so I'm not sure if the declaration is
:*exactly* correct; however, I did a test in Visual C++, and had no problem
:calling the routine, so I think I understand the arguments.  I've tried
:changing the declaration around as many ways as I can think: ByVal vs.
:ByRef, Integer vs. Long, etc., but no luck.  By the way, the "pth" argument
:is fine -- I pass it to the API function "GetShortPathName" a few lines
:above and have no problems.
:
:Any ideas?
:
:TIA,
:
:Mike
:
:
:
:



Sun, 31 Dec 2000 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Using SHAddToRecentDocs to populate Documents menu

2. populating document properties from text in document

3. SHAddToRecentDocs Problem

4. shaddtorecentdocs not functioning properly

5. How do you use SHAddToRecentDocs?

6. Populate a UserForm from document

7. How to populate the list box and how to return to specific part of document

8. Populate dropdow menus from access data

9. Populate Form with Selected values from dropdown menus

10. Question : How to Dynamically populate a popup menu :-) ???

11. Question : How to Dynamically populate a popup menu :-) ???

12. Question : How to Dynamically Populate a Popup Menu :-) ???

 

 
Powered by phpBB® Forum Software