Hello,

i have made an attempt at this to show im not lazy, but this currently doesnt work, it would mean the world to me if someone could help me finish this code asap, thanks again.

NOTE: Im trying to make this into a DLL for one of my projects

ORIGINAL

using System;
using System.Runtime.InteropServices;

namespace FejesJoco
{
    class Program
    {
        [DllImport("shell32.dll", EntryPoint = "#262", CharSet = CharSet.Unicode, PreserveSig = false)]
        public static extern void SetUserTile(string username, int whatever, string picpath);

        [STAThread]
        static void Main(string[] args)
        {
            SetUserTile(args[0], 0, args[1]);
        }
    }
}

AUTOIT SCRIPT

$sUserName = "username"
$sPicPath = "usertile.png"

; call CoInitialize
DLLCall("ole32.dll","int","CoInitialize","ptr",0)

$hPicPath = DLLStructCreate("wchar[128]")
DllStructSetData($hPicPath, 1, $sPicPath)

$hUserName = DLLStructCreate("wchar[128]")
DllStructSetData($hUserName, 1, $sUserName)

$aRet = DllCall(@SystemDir & "\shell32.dll", "long", 262, "ptr", DllStructGetPtr($hUserName), "int", 0, "ptr", DllStructGetPtr($hPicPath))

MsgBox(4096, "SetUserTile", $aRet[0])

TRANSLATION

#using <mscorlib.dll>
using namespace System;
using namespace System::Runtime::InteropServices;
 
#define DLL_EXPORT extern "C" __declspec(dllexport)
 
DLL_EXPORT long* SetUserTile(char* username char* imagepath) {
  
    CoInitialize();
  
    [DllImport("shell32.dll", EntryPoint = "#262", CharSet = CharSet.Unicode, PreserveSig = false)]
    public static extern void SetUserTile(string username, int whatever, string picpath);
    SetUserTile(username, 0, imagepath);
  
    CoUninitialize();
}

Its probably laughable, but im still learning, any help given is appreciated, thanks

Best Wishes,
Nathaniel Blackburn

Edited 5 Years Ago by nblackburn: n/a

In C++ instead of having "using System;", you would write something along the lines of "#include <iostream>". You're going to have to find the right include files, for what you want to do (which seems like iostream, and windows.h would be all your include files for this program). Also, you neglected to put "using namespace std;" after your includes, (while this isn't necessary, it makes life easier for longer programs). And finally, look up "Data Structures in C++", it seems most of your issues are there.

Assuming that shell32.dll exports a function with that signature with the entry point at ordinal 262,

a. Load shell32.dll into the process address space.
b. Get the address of the function at ordinal 262
c. Call the function.

Something like:

#include <windows.h>

int main()
{
   CoInitialize(0) ;
   {
       const char* const DLLNAME = "shell32.dll" ;
       enum { ORDINAL = 262 } ;
       typedef void __stdcall function_type( const wchar_t*, int, const wchar_t* ) ;
       typedef function_type* function_pointer_type ;

       function_pointer_type function_pointer = function_pointer_type(
                                        GetProcAddressA( LoadLibrary(DLLNAME),
                                        reinterpret_cast<const char*>(ORDINAL) ) ) ;

       wchar_t user_name[] = L"put user name here" ;
       wchar_t path[] = L"put path to picture file here" ;

       function_pointer( user_name, 0, path ) ;
   }
   CoUninitialize() ;
}

(Error handling is elided).

This article has been dead for over six months. Start a new discussion instead.