From: sebastian.martens on
Hi,

I just wrote a small assembly in C#, that I want to use with Visual
Objects. I registered the assembly and used the VO wizard to add a
stub for my COM object. Unfortuantely whenever I want to call a method
(SayHelloForeigner) of my assembly VO comes with an error "OLE
AutoObject has not been initialized or is already destroyed".

Does somebody knows why?

My C# code:
public interface IHello {
string SayHelloForeigner();
string SayHello(string sName);
}

[ClassInterface(ClassInterfaceType.None)]
public class HelloImpl:IHello {

public HelloImpl() {
}

public string SayHelloForeigner() {
return "Hello foreigner";
}

public string SayHello(string sName) {
return "Hello " + sName;
}
}

And the VO Code:
CLASS IHello INHERIT OLEAutoObject
METHOD Init(ObjID, fROTCHECK) CLASS IHello

IF (ObjID=NIL)
ObjId := "COMTest.HelloImpl"
ENDIF
//SUPER:Init(ObjID, 0, .T., fRotCheck)
SUPER:INit(ObjID, 0, .T.)
SELF:dwFuncs := 9
SELF:dwVars := 0
RETURN SELF
METHOD SayHelloForeigner( ) CLASS IHello

LOCAL oMethod AS cOleMethod
LOCAL uRetValue AS USUAL
LOCAL aArray AS ARRAY
LOCAL pRetDesc IS VOOLEARGDESC

pRetDesc.dwIDLFlag := 0
pRetDesc.dwVarType := VT_VOID

oMethod := cOleMethod{}
oMethod:symName := String2Symbol("SayHelloForeigner")
oMethod:iMemberid := 1610743808
oMethod:wInvokeKind := INVOKE_METHOD
oMethod:bRetType := VT_BSTR

aArray := {String2Symbol("SayHelloForeigner"), 1610743808,
INVOKE_METHOD, 0, 0, .F., , @pRetDesc}

//uRetValue := SELF:__Invoke(oMethod, DWORD(_BP+16),PCount())
uRetValue := SELF:__InvokeMethod(aArray, DWORD(_BP+16),PCount())

RETURN (uRetValue)

Regards
Sebastian

From: Anonymous on
Sebastian, I am using
[ClassInterface(ClassInterfaceType.AutoDual)]

Ed

<sebastian.martens(a)kms.de> wrote in message
news:1170781343.750639.136470(a)p10g2000cwp.googlegroups.com...
> Hi,
>
> I just wrote a small assembly in C#, that I want to use with Visual
> Objects. I registered the assembly and used the VO wizard to add a
> stub for my COM object. Unfortuantely whenever I want to call a method
> (SayHelloForeigner) of my assembly VO comes with an error "OLE
> AutoObject has not been initialized or is already destroyed".
>
> Does somebody knows why?
>
> My C# code:
> public interface IHello {
> string SayHelloForeigner();
> string SayHello(string sName);
> }
>
> [ClassInterface(ClassInterfaceType.None)]
> public class HelloImpl:IHello {
>
> public HelloImpl() {
> }
>
> public string SayHelloForeigner() {
> return "Hello foreigner";
> }
>
> public string SayHello(string sName) {
> return "Hello " + sName;
> }
> }
>
> And the VO Code:
> CLASS IHello INHERIT OLEAutoObject
> METHOD Init(ObjID, fROTCHECK) CLASS IHello
>
> IF (ObjID=NIL)
> ObjId := "COMTest.HelloImpl"
> ENDIF
> //SUPER:Init(ObjID, 0, .T., fRotCheck)
> SUPER:INit(ObjID, 0, .T.)
> SELF:dwFuncs := 9
> SELF:dwVars := 0
> RETURN SELF
> METHOD SayHelloForeigner( ) CLASS IHello
>
> LOCAL oMethod AS cOleMethod
> LOCAL uRetValue AS USUAL
> LOCAL aArray AS ARRAY
> LOCAL pRetDesc IS VOOLEARGDESC
>
> pRetDesc.dwIDLFlag := 0
> pRetDesc.dwVarType := VT_VOID
>
> oMethod := cOleMethod{}
> oMethod:symName := String2Symbol("SayHelloForeigner")
> oMethod:iMemberid := 1610743808
> oMethod:wInvokeKind := INVOKE_METHOD
> oMethod:bRetType := VT_BSTR
>
> aArray := {String2Symbol("SayHelloForeigner"), 1610743808,
> INVOKE_METHOD, 0, 0, .F., , @pRetDesc}
>
> //uRetValue := SELF:__Invoke(oMethod, DWORD(_BP+16),PCount())
> uRetValue := SELF:__InvokeMethod(aArray, DWORD(_BP+16),PCount())
>
> RETURN (uRetValue)
>
> Regards
> Sebastian
>