What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » Interop.Call windows shell help

Interop.Call windows shell help
Author: Message:
wincy
Junior Member
**


Posts: 67
Reputation: 4
34 / Male / Flag
Joined: Feb 2008
O.P. Interop.Call windows shell help
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...
11-08-2009 08:19 PM
Profile E-Mail PM Find Quote Report
Spunky
Former Super Mod
*****

Avatar

Posts: 3658
Reputation: 61
35 / Male / Flag
Joined: Aug 2006
RE: Interop.Call windows shell help
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)
<Eljay> "Problems encountered: shit blew up" :zippy:
11-08-2009 08:24 PM
Profile PM Find Quote Report
wincy
Junior Member
**


Posts: 67
Reputation: 4
34 / Male / Flag
Joined: Feb 2008
O.P. RE: Interop.Call windows shell help
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

This post was edited on 11-09-2009 at 12:11 AM by wincy.
11-09-2009 12:10 AM
Profile E-Mail PM Find Quote Report
CookieRevised
Elite Member
*****

Avatar

Posts: 15519
Reputation: 173
– / Male / Flag
Joined: Jul 2003
Status: Away
RE: RE: Interop.Call windows shell help
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.

This post was edited on 11-10-2009 at 07:55 AM by CookieRevised.
.-= A 'frrrrrrrituurrr' for Wacky =-.
11-09-2009 01:22 AM
Profile PM Find Quote Report
wincy
Junior Member
**


Posts: 67
Reputation: 4
34 / Male / Flag
Joined: Feb 2008
O.P. RE: RE: RE: Interop.Call windows shell help
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!
11-09-2009 03:26 PM
Profile E-Mail PM Find Quote Report
Ezra
Veteran Member
*****

Avatar
Forgiveness is between them and God

Posts: 1960
Reputation: 31
37 / Male / Flag
Joined: Mar 2003
RE: Interop.Call windows shell help
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).
[Image: 1-0.png]
             
11-09-2009 04:15 PM
Profile PM Web Find Quote Report
matty
Scripting Guru
*****


Posts: 8336
Reputation: 109
39 / Male / Flag
Joined: Dec 2002
Status: Away
RE: Interop.Call windows shell help
Does something like this help at all?

http://msdn.microsoft.com/en-us/library/bb776297%28VS.85%29.aspx
11-09-2009 05:32 PM
Profile E-Mail PM Find Quote Report
CookieRevised
Elite Member
*****

Avatar

Posts: 15519
Reputation: 173
– / Male / Flag
Joined: Jul 2003
Status: Away
RE: Interop.Call windows shell help
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.
.-= A 'frrrrrrrituurrr' for Wacky =-.
11-10-2009 07:51 AM
Profile PM Find Quote Report
Ezra
Veteran Member
*****

Avatar
Forgiveness is between them and God

Posts: 1960
Reputation: 31
37 / Male / Flag
Joined: Mar 2003
RE: Interop.Call windows shell help
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#
[Image: 1-0.png]
             
11-11-2009 10:55 PM
Profile PM Web Find Quote Report
« Next Oldest Return to Top Next Newest »


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On