Jump to content



Photo

Translating this autoit script into c++


  • Please log in to reply
9 replies to this topic

#1 nblackburn

nblackburn

    Seeker

  • New Members
  • 2 posts

Posted 02 September 2011 - 02:20 AM

Hello,

this is my very first post, i have found this awesome script on your forum and was wondering if you lovely people would help me translate it into c++ so i can use it with one of my projects.

$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])


Thanks to anyone that helps, it means alot

Kind Regards,
Nathaniel Blackburn







#2 nblackburn

nblackburn

    Seeker

  • New Members
  • 2 posts

Posted 02 September 2011 - 02:49 AM

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.

#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(); }


Best Wishes,
Nathaniel Blackburn

Edited by nblackburn, 02 September 2011 - 02:49 AM.


#3 MvGulik

MvGulik

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 2,795 posts

Posted 02 September 2011 - 02:58 AM

Erm ... Think you got things mixed up a bit. This section is for AutoIt Help and not C(With or without additional plus tags.)

Suggest you ask your topic to be moved (ASAP -> use report button). to 'Chat' ... or 'Dev' forum, latter probably more fun for others forum users.

#4 jaberwocky6669

jaberwocky6669

    Dull light.

  • Active Members
  • PipPipPipPipPipPip
  • 2,118 posts

Posted 02 September 2011 - 09:31 AM

I've looked into and I've determined that my visual c++ skills are sorely lacking. However, I'll bet that if you include some error messages then someone might come along and help you out.

#5 Richard Robertson

Richard Robertson

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 9,716 posts

Posted 02 September 2011 - 01:42 PM

You seem to have mixed up C# and C++. You've got some code from both in there.

#6 jaberwocky6669

jaberwocky6669

    Dull light.

  • Active Members
  • PipPipPipPipPipPip
  • 2,118 posts

Posted 03 September 2011 - 10:02 AM

Hah, so it isn't even visualc++? I see I need to branch out and learn some more languages.

#7 Richard Robertson

Richard Robertson

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 9,716 posts

Posted 03 September 2011 - 01:21 PM

It is Visual C++, but it is the managed extensions (or whatever they are currently called). There's really no reason to use it. Straight VC++ or switching to C# would be tons easier.

#8 progrogrammer

progrogrammer

    Seeker

  • New Members
  • 3 posts

Posted 10 September 2011 - 11:36 PM

I don't think this is C++ a 100%. For example wtf does [] do? Never saw it in any language. Also "public static extern void SetUserTile(string username, int whatever, string picpath);"
In C++ you don't need the "public static extern" part, you just declare a function like RetType name(blablabla);

So what exactly error messages do you get? I am to lazy to paste this into the compiler myself xD

#9 progrogrammer

progrogrammer

    Seeker

  • New Members
  • 3 posts

Posted 10 September 2011 - 11:48 PM

#using <mscorlib.dll>

in C++ you have to type #include <stuff> but I am not sure for Managed C++



using namespace System;
using namespace System::Runtime::InteropServices;
The second using cancels the first one so decide, using system or using system:runtime:interopstuffff

The only way I see this is an attempt to write a C++ code, ise because of the #define

And take out public in your function declaration, and you also have to define the function somewhere

#10 Richard Robertson

Richard Robertson

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 9,716 posts

Posted 11 September 2011 - 03:13 PM

progrogrammer, what he is writing is managed C++, and what he is doing is fine.

Also, you need to learn some C++. Multiple "using namespace" statements are fine. It just imports everything in those namespaces to the local root.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users