Need help declaring PathCleanupspec

B

Buddy Robbins

Hey folks,
I'm trying to use the PathCleanupSpec function from the shell library.

The function prototype is:
int PathCleanupSpec( LPCWSTR pszDir, LPWSTR pszSpec)

In the old days of VB6, I would make the parameters Longs, and use the
StrPtr function.
Begin new to Dot Net, I can't figure out how to make this beast work.

Can someone tell me how to prototype the Declare function for this?

Thanks in advance,
-Buddy Robbins
 
G

Guest

Hi

I am not sure if I have this correct, but here is what I think:

Imports:

Imports System.Runtime.InteropServices ' For DLLImport
Imports System.Text ' For StringBuilder

Constants:

Public Const PCS_REPLACEDCHARS As Integer = &H1
Public Const PCS_REMOVEDCHARS As Integer = &H2
Public Const PCS_SHORTENED As Integer = &H4
Public Const PCS_PATHTOOLONG As Integer = &H8
Public Const PCS_FATAL As Integer = &H8000000

Function:

Public Declare Unicode Function PathCleanupSpec Lib "Shell32.dll" _
(ByVal pszDir As StringBuilder, _
<MarshalAs(UnmanagedType.LPWStr)> _
ByVal pszSpec As String) As Integer

or

<DllImport("shell32.dll", CallingConvention:=CallingConvention.StdCall, _
CharSet:=CharSet.Unicode, entrypoint:="PathCleanUpSpecAW")> _
Public Shared Function PathCleanupSpec _
(ByVal pszDir As StringBuilder, _
<MarshalAs(UnmanagedType.LPWStr)> _
ByVal pszSpec As StringBuilder) As Integer
End Function

-----------------------------------------------------------------------------------------

Ok, looking in the Platform SDK (Feb 2003) at the function you asked about
it mentions that the strings need to be NULL terminated Unicode strings.

An LPCWSTR according to the .NET Framework SDK needs to be declared as
System.Text.StringBuilder, but can be declared as a string

The LPWStr is a NULL terminated 2-byte unicode string

The constants are declared in shlObj.h. All of them seem to be ok as an
integer, but if you declare the PCS_FATAL as a decimal then the number is out
of an integer scope. So, maybe you'll need to declare them as Int32.

I haven't tested the above because I have no use for it, but please let me
know the correct solution, if the above information is incorrect.

I hope this helps
 
B

Buddy Robbins

Thanks for the assist, 'Crouchie'

In general, if there is an operating system function that performs a task, I
would use it before writing my own. In this case, we are really watching
our pennies on this project, so I was allowed to spend 15 minutes this
morning to get this to work. Well, I couldn't get the solution to run in
the time allotted, so I had to write my own routine (granted it was a
simple routine, but it's the principle).

Thanks for the assist, and I'll try to get it working on my own time.

-Buddy Robbins
 
G

Guest

Tell me exactly what you want & I will try & code it for you. I will have
time later to spend a few hours if you need
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top