Jump to content

trying CoCreateInstance API


WSCPorts
 Share

Recommended Posts

STDAPI CoCreateInstance(

  REFCLSID rclsid,

  LPUNKNOWN pUnkOuter,

  DWORD dwClsContext,

  REFIID riid,

  LPVOID * ppv

 )

   Function GetModules( _; this is what i want to use after Cocreateinstance  
;return  a point to the interface 
  ByVal  applicationDir As String, _
  ByVal  applicationName As String, _
  ByVal  assemblyName As String _
 ) As String()

i Get no Errors yet nothing shows up

$CLSCTX_INPROC_SERVER = 1
$CLSCTX_INPROC_HANDLER = 2
$CLSCTX_LOCAL_SERVER = 4
$CLSCTX_ALL = BitOr($CLSCTX_INPROC_SERVER , $CLSCTX_INPROC_HANDLER, $CLSCTX_LOCAL_SERVER)
Func CoCreateInst($rclsid, $pUnkOuter, $dwClsContext, $riid, $ppv)

$Ret = DllCall("Ole32.dll", "ptr", "CoCreateInstance", "str", $rclsid, "int", $pUnkOuter, _
"int", $CLSCTX_ALL,  "ptr", $ppv)
$Ret = $ppv
Return $Ret
EndFunc;;==>End CoCreatInst

Dim $instObj, $Ole, $CallObj
$CallObj = CoCreateInst("GUID_AssemblyLocator", 0, $CLSCTX_ALL, "System.EnterpriseServices.Internal.AssemblyLocator", $instObj)
$Ole = ObjCreate($CallObj)
$Name = ObjName($Ole)
Msgbox(0, "ObjName", $Name)


Dim $Struct = "Char;Char;char"
$cStruct = DllStructCreate($struct)
Func ModuleGet( $applicationDir, $applicationName, $assemblyName )
DllStructSetData($cStruct, 1, $applicationDir)  
DllStructSetData($cStruct, 2, $applicationName)
DllStructSetData($cStruct, 2, $assemblyName)
$Ole.GetModules(DllStructGetData($cStruct, 1), DllStructGetData($cStruct, 2)_
DllStructGetData($cStruct, 3)
DllStructDelete($cStruct)
EndFunc
EndWith 

Dim $modNames = ModuleGet("C:\Windows\Micros~1\Framework\v2.0.50215", "IEExec.exe", "System")
  For $i = 0 to $modName
MsgBox(0, "module Name", $modNames($i))
$i = $i + 1
Next
Edited by WSCPorts
http://www.myclanhosting.com/defiasVisit Join and contribute to a soon to be leader in Custumized tools development in [C# .Net 1.1 ~ 2.0/C/C++/MFC/AutoIt3/Masm32]
Link to comment
Share on other sites

no messagebox's show up so i cant tell wheres its failing pls help ///

$CLSCTX_INPROC_SERVER = 1
$CLSCTX_INPROC_HANDLER = 2
$CLSCTX_LOCAL_SERVER = 4
$CLSCTX_ALL = BitOr($CLSCTX_INPROC_SERVER , $CLSCTX_INPROC_HANDLER, $CLSCTX_LOCAL_SERVER)
Dim $Struct = "Char;Char;char"
$cStruct = DllStructCreate($struct)

Dim $Ret[1] 
Func CoCreateInst($rclsid, $pUnkOuter, $dwClsContext, $riid, $ppv)
$Ret[0] = DllCall("Ole32.dll", "ptr", "CoCreateInstance", "str", $rclsid, "int", $pUnkOuter, _
"int", $CLSCTX_ALL,  "long_ptr", $ppv)
MsgBox(0, "Return FuncVal", $Ret) 
$Ret[1] = $ppv
MsgBox(0, "Return Object", ObjName($Ret[1]))
Return $Ret[1]
EndFunc;;==>End CoCreatInst

Func ModuleGet( $applicationDir, $applicationName, $assemblyName )
DllStructSetData($cStruct, 1, $applicationDir)  
DllStructSetData($cStruct, 2, $applicationName)
DllStructSetData($cStruct, 2, $assemblyName)
$Ole.GetModules(DllStructGetData($cStruct, 1), DllStructGetData($cStruct, 2)_
DllStructGetData($cStruct, 3)
DllStructDelete($cStruct)
EndFunc
EndWith 
$null = chr(0)

Dim $instObj, $Ole, $CallObj
$CallObj = CoCreateInst("GUID_AssemblyLocator", $null, $CLSCTX_ALL, "System.EnterpriseServices.Internal.AssemblyLocator", $instObj)
$Ole = ObjCreate($instObj)
$Name = ObjName($Ole)
Msgbox(0, "ObjName", $Name)

$modNames = ModuleGet("C:\Windows\Micros~1\Framework\v2.0.50215", "IEExec.exe", "IEHost.dll")
$i = 0
  For $i to $modName
MsgBox(0, "module Name", $modNames($i))
$i = $i + 1
Next
http://www.myclanhosting.com/defiasVisit Join and contribute to a soon to be leader in Custumized tools development in [C# .Net 1.1 ~ 2.0/C/C++/MFC/AutoIt3/Masm32]
Link to comment
Share on other sites

I have no idea what you are actually trying to achieve, but my suggestion is to not play with COM in this manner unless you have a background of creating and instantiating COM objects without using ATL in C++. You are not even close to instantiating a COM object with that code. In fact, I'm surprised that you aren't crashing AutoIt because you have very few parameters right. What you are doing is basically futile. COM is not a subject in which you can read just a little and then write code in a language that doesn't even support what you are trying to do (or does it? I don't know, your code is hard to read because it does nothing right). I'm not trying to be mean or degrading here, but this is something you obviously don't know about and will not know about just from reading. COM is one of the most complex Window's programming concepts to grasp.

Link to comment
Share on other sites

show me where im wrong im am more than willing to learn...

Everywhere.

and i know im not even close yet ...  maybe a clue, and maybe i learn as i go :whistle:

You need more than a clue and you will not learn COM using AutoIt as you go. The subject is too complex. Also, you will not be able to call methods on a COM object, even if you do manage to get it instantiated. If it doesn't have an IDispatch interface, you can't use it with AutoIt. If it has an IDispatch interface, you can use ObjCreate() to instantiate it. You don't understand AutoIt, COM or the windows architecture enough to pursue your current path and you will not learn them as you go; the concepts are just too vastly difficult to understand for that.

As I said above, tell us what you are trying to achieve. We may be able to help you find a solution to your problem if you explain the problem. The road you are going now leads nowhere.

Link to comment
Share on other sites

Creation of Dispatch API Functions

For 32-bit systems, dispatch functions are provided in the file Oleaut32.dll. The header file is Oleauto.h, and the import library is Oleaut32.lib. For 16-bit systems, the dispatch functions are provided in the file Oledisp.dll. The header file is Dispatch.h, and the import library is Ole2disp.lib. These functions simplify the creation of IDispatch interfaces. The dispatch functions are summarized in the following table.

Functions Description

CreateDispTypeInfo Creates simplified type information for an object.

CreateStdDispatch Creates a standard IDispatch implementation for an object.

DispGetIDsOfNames Converts a set of names to DISPIDs.

DispGetParam Retrieves and coerces elements from a DISPPARAMS structure.

DispInvoke Calls a member function of an IDispatch interface.

@Valik i want to Create Dispatch interfaces for Objects in autoit

then i want to be able to initialize them for use accross applications.

and am i using the wrong parameters for the dllCall or just everywhere is wrong any help would be apreeciated.

http://www.myclanhosting.com/defiasVisit Join and contribute to a soon to be leader in Custumized tools development in [C# .Net 1.1 ~ 2.0/C/C++/MFC/AutoIt3/Masm32]
Link to comment
Share on other sites

Everything is wrong. You function calls are wrong, your parameters are wrong, your logic is wrong.

Regarding what you are trying to do, I think you are in way over your head.

  • AutoIt is not designed to create IDispatch-enabled COM objects (Or any COM object for that matter). AutoIt is a client only, not a server.
  • COM is not a subject for the meek. Its not as complex as it's made out to be but it's far more complex than many other Windows concepts.
  • Creating IDispatch interface is not something you need to worry about unless you are creating automation enabled interfaces. Creating automation enabled interfaces is not something you start out doing in COM.
You're using the wrong tools with none of the massive amounts of knowledge you need. If you are going to learn COM, you need a low-level language able to compile the objects into the binary format COM expects; AutoIt is not that language. You need C++ or similar for that.
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...