Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The documentation is confusing, but correct. The MSDN page you reference helps to explain why your <code>GetObject</code> call doesn't throw an error:</p> <blockquote> <p>If <strong><em>pathname</em></strong> [<em>the first argument</em>] is a zero-length string (""), <strong>GetObject</strong> returns a new object instance of the specified type. If the pathname argument is omitted, <strong>GetObject</strong> returns a currently active object of the specified type. If no object of the specified type exists, an error occurs.</p> </blockquote> <p>It's subtle, but the implication is that </p> <pre><code>GetObject "", "ProjectName.ClassName </code></pre> <p>is actually equivalent to </p> <pre><code>CreateObject "ProjectName.ClassName" </code></pre> <p>That is to say, passing an empty string to the first parameter of <code>GetObject</code> makes it operate exactly like <code>CreateObject</code>, which means it will create a <strong>new instance</strong> of the class, rather than returning a reference to an already-running instance.</p> <p>Going back to the MSDN excerpt, it mentions that omitting the first argument to <code>GetObject</code> altogether will cause <code>GetObject</code> to return a reference to an already-running instance, if one exists. Such a call would look like this:</p> <pre><code>GetObject , "ProjectName.ClassName" 'Note nothing at all is passed for the first argument' </code></pre> <p>However, if you try to do this, you will immediately get a run-time error. This is the use-case that the documentation is referring to when it says that <code>GetObject</code> doesn't work with classes created with VB6. </p> <p>The reason this doesn't work is due to how <code>GetObject</code> performs its magic. When the first parameter is omitted, it tries to return an existing object instance by consulting the Running Object Table (ROT), a machine-wide lookup table that contains running COM objects. The problem is that objects have to be explicitly registered in the Running Object Table by the process that creates them in order to be accessible to other processes - the VB6 runtime doesn't register ActiveX EXE classes in the ROT, so <code>GetObject</code> has no way to retrieve a reference to an already-running instance.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload