Shoutbox

Interop.Call windows shell help - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Messenger Plus! for Live Messenger (/forumdisplay.php?fid=4)
+---- Forum: Scripting (/forumdisplay.php?fid=39)
+----- Thread: Interop.Call windows shell help (/showthread.php?tid=92863)

Interop.Call windows shell help by wincy on 11-08-2009 at 08:19 PM

Hello guys,
Can someone please help me with EstimateFileRiskLevel function in Windows Shell with Interop.Call?

I read official documentation here but i found it not simple enough..

I wrote this:

code:
function test() {
var MAX_PATH = 260;
var url = "C:\Documents and Settings\MyName\Desktop\myfile.exe"
var result = Interop.Allocate((MAX_PATH+1)*2);

Interop.Call('shell32.dll', 'EstimateFileRiskLevel', url, ".exe", pszHandler, result);

return result;
}

but i don't know what to use as a handler ("pszHandler").
Can someone help me on this?
Thanks in advance...
RE: Interop.Call windows shell help by Spunky on 11-08-2009 at 08:24 PM

I think pszHandler may be a path to Notepad (for txt files) for example...

I think you're reading the result wrong btw and may want to return result.ReadString or something similar (not too good with datablocks)


RE: Interop.Call windows shell help by wincy on 11-09-2009 at 12:10 AM

I tried this:

code:
function test() {
    var MAX_PATH = 260;
    var url = "C:\Documents and Settings\Vincy\Desktop\headers.txt";
    var han = "C:\WINDOWS\notepad.exe";
    var result = Interop.Allocate((MAX_PATH+1)*2);

    Interop.Call('shell32.dll', 'EstimateFileRiskLevel', url, ".txt", han, result);
    var result = result.ReadString(0, false);
    return result;
}


But debug says something like:
CallDll failed collocation of function "EstimateFileRiskLevel"...

What should i do? How should i read the result?
Thanks
RE: RE: Interop.Call windows shell help by CookieRevised on 11-09-2009 at 01:22 AM

quote:
Originally posted by wincy

But debug says something like:
CallDll failed collocation of function "EstimateFileRiskLevel"...

What should i do? How should i read the result?
Thanks
The correct error you get is:
"Interop.Call failed to locate function "EstimateFileRiskLevel""
Remember it is absolutely very important to always paste errors correctly and exactly when you're seeking help. <- EDIT: sorry, it didn't occured to me you translated it yourself. It's best to post the original error, in your own language though.

Anyways, the error says it can not locate the function you are trying to execute in the library you told to seek in. In other words, you are using either the wrong name of the function, or you tell it to seek it in the wrong library, or both...

In this case, if you read the documentation on MSDN, it is both. The function name is wrong and the library is wrong:
quote:
Remarks
This function is not declared in a public header or included in a library file. To use it you must load it directly from Winshfhc.dll by ordinal 101.
So, the library is 'Winshfhc.dll', not 'Shell32.dll'.
But it also means that you can't use Interop.Call to call this function as it does not have a public name and Interop.Call can not work with ordinal numbers.

In other words: you can not use this Windows API in this way.
RE: RE: RE: Interop.Call windows shell help by wincy on 11-09-2009 at 03:26 PM

quote:
Originally posted by CookieRevised

The correct error you get is:
"Interop.Call failed to locate function "EstimateFileRiskLevel""
Remember it is absolutely very important to always paste errors correctly and exactly when you're seeking help.

Sorry, the debuggers display errors in my language, i tried to translate it by myself.

quote:
Originally posted by CookieRevised

In other words: you can not use this Windows API in this way.

Thanks anyway for your help!
RE: Interop.Call windows shell help by Ezra on 11-09-2009 at 04:15 PM

I tried creating a C# wrapper for the function however this is the first time I'm attempting to use unsafe code in C# and my C# skills are lacking anyway, so I'm running into some walls.

I can't read the result from the function, maybe anyone here knows what I'm doing wrong?

C# code:
using System;
using System.Runtime.InteropServices;

namespace EstimateFileRiskLevelWrapper
{
    public class EstimateFileRiskLevelWrapper
    {
        [DllImport("winshfhc.dll", EntryPoint = "#101")]
        public static extern int EstimateFileRiskLevel([MarshalAs(UnmanagedType.LPWStr)] String pszFilePath, [MarshalAs(UnmanagedType.LPWStr)] String pszExt, [MarshalAs(UnmanagedType.LPWStr)] String pszHandler, ref IntPtr riskLevel);
        /*HRESULT EstimateFileRiskLevel(
            LPCWSTR pszFilePath,
            LPCWSTR pszExt,
            LPCWSTR pszHandler,
            FILE_RISK_LEVEL *pfrlEstimate
        );*/
    }
}

Trying to use the function with:
C# code:
EstimateFileRiskLevelWrapper.EstimateFileRiskLevelWrapper.EstimateFileRiskLevel(
                    fpath,
                    ".php",
                    hpath,
                    ref risklevel);
                IntPtr ptr = Marshal.ReadIntPtr(risklevel);

but I'm getting an AccessViolationException at the last line (reading the pointer).
RE: Interop.Call windows shell help by matty on 11-09-2009 at 05:32 PM

Does something like this help at all?

http://msdn.microsoft.com/en-us/library/bb776297%28VS.85%29.aspx


RE: Interop.Call windows shell help by CookieRevised on 11-10-2009 at 07:51 AM

quote:
Originally posted by matty
Does something like this help at all?

http://msdn.microsoft.com/en-us/library/bb776297%28VS.85%29.aspx
yeah, that is the interface one should be using instead...

But I never worked with stuff like that before in Plus! scripting. It has DataBloc::ReadInterfacePtr but I never used it.
RE: Interop.Call windows shell help by Ezra on 11-11-2009 at 10:55 PM

Going a bit offtopic, but does anyone know why i'm getting the errors i'm getting in my above C# test?

Would help me out a lot with my understanding of unsafe/unmanaged code in C#