Click here to Skip to main content
16,011,120 members
Home / Discussions / C#
   

C#

 
GeneralRe: How to get number of running threads? Pin
CWIZO24-Feb-04 4:08
CWIZO24-Feb-04 4:08 
GeneralWin32 to .NET Framework API Map Pin
Kant23-Feb-04 9:10
Kant23-Feb-04 9:10 
GeneralRe: Win32 to .NET Framework API Map Pin
Kentamanos23-Feb-04 11:10
Kentamanos23-Feb-04 11:10 
GeneralRe: Win32 to .NET Framework API Map Pin
Alexsander Antunes1-Mar-04 7:52
professionalAlexsander Antunes1-Mar-04 7:52 
GeneralChanging border color in a Win Button control. Pin
jose.cebrian23-Feb-04 8:51
sussjose.cebrian23-Feb-04 8:51 
GeneralRe: Changing border color in a Win Button control. Pin
Heath Stewart23-Feb-04 9:16
protectorHeath Stewart23-Feb-04 9:16 
GeneralRe: Changing border color in a Win Button control. Pin
jose.cebrian23-Feb-04 22:31
sussjose.cebrian23-Feb-04 22:31 
GeneralCOM - STRRET Issues Pin
Tristan Rhodes23-Feb-04 8:34
Tristan Rhodes23-Feb-04 8:34 
I'm trying to run the GetDisplayName method of a folder (in this case, the desktop folder). It all executes perfectly as far as I can see, until it reaches the StrRetToStr method, where it crashes with a null pointer error.

I'm slightly confused as its practicaly identical to the tutorial on this site, and all values forwarded are allocated succesfuly by previous functions.

The code follows:


			//Allocate Desktop pidl<br />
			IntPtr desktopPIDL = new IntPtr();<br />
<br />
			//Get desktop folder<br />
			COMStuff.SHGetDesktopFolder(out desktopPIDL);<br />
<br />
			//Set Shell interface type<br />
			Type shellType = typeof(IShellFolder);<br />
<br />
			//Build COM object<br />
			IShellFolder shellFolder = (IShellFolder)<br />
				Marshal.GetTypedObjectForIUnknown(desktopPIDL, shellType);<br />
<br />
<br />
			//Alcoate Interface ptr and relative PIDL ptr<br />
			IntPtr interfacePtr = new IntPtr();<br />
			IntPtr relativePIDL = new IntPtr();<br />
			<br />
			//Get GUID<br />
			Guid myGUID = Marshal.GenerateGuidForType(shellType);<br />
			<br />
			//Bind to parent<br />
			result = COMStuff.SHBindToParent(desktopPIDL,<br />
				myGUID,		//GUID!<br />
				out interfacePtr,<br />
				out relativePIDL);<br />
<br />
			//Build myShellFolder<br />
			IShellFolder myShellFolder = (IShellFolder)Marshal.GetTypedObjectForIUnknown(interfacePtr,shellType);<br />
<br />
			//NOTE: Must be tied to parent folder!<br />
			//Allocate STRRET<br />
			mySTRRET = new STRRET();<br />
			//Get relative PIDL<br />
			result = myShellFolder.GetDisplayNameOf(relativePIDL,SHGDN_Flags.SHGDN_NORMAL | SHGDN_Flags.SHGDN_FORPARSING<br />
						,ref mySTRRET);<br />
			//mySTRRET.uType = 2;<br />
<br />
<br />
			//Allocate File name string<br />
			myFileName = new string(' ',128);<br />
<br />
			//Run Conversion<br />
			result = COMStuff.StrRetToStr(mySTRRET, relativePIDL, out myFileName);	



The calling code above gets to the last line before crashing.. STRRET has all it's values set to the same PIDL, which is expected, as the type is identifiened by the type value. However, the type value remains 0 regardless of the flags on the STRRET structure returned by the GetDisplayName of.

The STRRET struct and the StrRetToStr method are declared as follows:

<br />
[StructLayout(LayoutKind.Explicit, CharSet = CharSet.Auto)]<br />
public struct STRRET<br />
{<br />
[FieldOffset(0)]<br />
public uint uType; //1 = PoleStr, 2 = int Offset, 3 = string (char[Max_Path])<br />
<br />
[FieldOffset(4)]<br />
public IntPtr pOleStr; //Pointer to the OLE string<br />
<br />
[FieldOffset(4)]<br />
public UInt32 uOffset; //Offset into the IID list<br />
<br />
[FieldOffset(4)]<br />
public IntPtr cStr; //String Pointer<br />
<br />
}<br />
<br />
<br />
<br />
[DllImport("shlwapi.dll", CharSet=CharSet.Auto)]<br />
public static extern int StrRetToStr(<br />
ref STRRET pstr,<br />
IntPtr pidl,<br />
[MarshalAs(UnmanagedType.BStr)]<br />
out string pbstring);<br />


I'm certain that the error lies in either the declaration of my STRRET structure, or the implementation of StrRetToStr.

I'm going to experiment with the alternative method as well, StrRetToBuf, but I susspect a similar problem will occur.

If anyone could shed some light on this subject, it would be most grateful.

regards

Cata
GeneralRe: COM - STRRET Issues Pin
Heath Stewart23-Feb-04 9:14
protectorHeath Stewart23-Feb-04 9:14 
GeneralRe: COM - STRRET Issues Pin
Tristan Rhodes23-Feb-04 9:41
Tristan Rhodes23-Feb-04 9:41 
GeneralRe: COM - STRRET Issues Pin
Heath Stewart23-Feb-04 11:31
protectorHeath Stewart23-Feb-04 11:31 
GeneralRe: COM - STRRET Issues Pin
Tristan Rhodes24-Feb-04 7:34
Tristan Rhodes24-Feb-04 7:34 
GeneralDraw text on path Pin
Werdna23-Feb-04 7:55
Werdna23-Feb-04 7:55 
GeneralRe: Draw text on path Pin
Heath Stewart23-Feb-04 9:10
protectorHeath Stewart23-Feb-04 9:10 
GeneralRe: Draw text on path Pin
Werdna23-Feb-04 14:28
Werdna23-Feb-04 14:28 
GeneralIs it possible to access a variable declared in c# in an html page Pin
VIJAYPAPUPAGER23-Feb-04 7:10
VIJAYPAPUPAGER23-Feb-04 7:10 
GeneralRe: Is it possible to access a variable declared in c# in an html page Pin
Nick Parker23-Feb-04 7:39
protectorNick Parker23-Feb-04 7:39 
GeneralRe: Is it possible to access a variable declared in c# in an html page Pin
Heath Stewart23-Feb-04 9:07
protectorHeath Stewart23-Feb-04 9:07 
GeneralThis is odd ! Pin
Ashwin C23-Feb-04 6:43
Ashwin C23-Feb-04 6:43 
GeneralRe: This is odd ! Pin
Heath Stewart23-Feb-04 6:48
protectorHeath Stewart23-Feb-04 6:48 
GeneralRe: This is odd ! Pin
Ashwin C23-Feb-04 6:59
Ashwin C23-Feb-04 6:59 
GeneralRe: This is odd ! Pin
Heath Stewart23-Feb-04 7:04
protectorHeath Stewart23-Feb-04 7:04 
GeneralRe: This is odd ! Pin
Ashwin C23-Feb-04 7:12
Ashwin C23-Feb-04 7:12 
GeneralRe: This is odd ! Pin
Heath Stewart23-Feb-04 8:57
protectorHeath Stewart23-Feb-04 8:57 
GeneralRe: This is odd ! Pin
Michael P Butler23-Feb-04 7:29
Michael P Butler23-Feb-04 7:29 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.