Windows 10: Cannot marshal from C# IReflect object to C++ IDispatch

Discus and support Cannot marshal from C# IReflect object to C++ IDispatch in Windows 10 Customization to solve the problem; HI, I am struggling with a problem for some time and I hope I can get some guidance here on the community forums. The problem is simple: I have a... Discussion in 'Windows 10 Customization' started by Claudiu_D, Jan 16, 2020.

  1. Claudiu_D Win User

    Cannot marshal from C# IReflect object to C++ IDispatch


    HI,


    I am struggling with a problem for some time and I hope I can get some guidance here on the community forums.

    The problem is simple:


    I have a com interface:


    [ComImport]
    [Guid"08D7DC4F-40A7-432D-A219-FE5470671DC3"]
    [TypeLibTypeTypeLibTypeFlags.FDual TypeLibTypeFlags.FNonExtensible TypeLibTypeFlags.FDispatchable]
    public interface IDispatchSupplier
    {
    [MethodImplMethodImplOptions.InternalCall]
    [DispId1610743809]
    [return: MarshalAsUnmanagedType.IDispatch]
    object GetMyObject[In] [MarshalAsUnmanagedType.BStr] string className;
    }


    and implemenation of IDispatchSupplier:


    [ComVisibletrue]
    [ProgId"Test.MyDispatchSupplier"]
    public sealed class DispatchSupplier: IDispatchSupplier
    {
    public object GetMyObjectstring className
    {
    MyReflectObject reflectObject = new MyReflectObject ;
    return reflectObject ;
    }
    }


    and a class that implements IReflect:


    [ComVisibletrue, ClassInterfaceClassInterfaceType.None]
    public sealed class MyReflectObject : IReflect
    {

    public MemberInfo[] GetMembersBindingFlags bindingAttr
    {
    return _membersArray;
    }

    //.......and so on, IReflect is implemented

    }



    From C++ I just want to access the ITypeInfoMembers and expecting to have members from IReflect but they are not there


    CComPtr<IDispatchSupplier> dispatchSupplier;
    if SUCCEEDEDdispatchSupplier.CoCreateInstanceL"Test.MyDispatchSupplier"
    {
    CComPtr<IDispatch> myDispatchObject;
    HRESULT hr = dispatchSupplier->GetMyObjectmicClass, &myDispatchObject;
    if SUCCEEDEDhr
    {
    CComPtr<ITypeInfo> myDispatchObjectTypeInfo;
    if SUCCEEDEDmyDispatchObject->GetTypeInfoNULL, NULL, &myDispatchObjectTypeInfo
    {
    TYPEATTR* spTypeAttr = nullptr;
    hr = myDispatchObjectTypeInfo->GetTypeAttr&spTypeAttr;
    //unique_ptr<TYPEATTR> aspTypeAttr;
    if SUCCEEDEDhr
    {
    WORD funcsCount = spTypeAttr->cFuncs;
    for WORD i = 0; i < funcsCount; i++
    {
    FUNCDESC* spfuncdesc = nullptr;
    UINT temp = i;
    hr = myDispatchObjectTypeInfo->GetFuncDesctemp, &spfuncdesc;
    //unique_ptr<FUNCDESC> bspfuncdesc;
    if SUCCEEDEDhr && spfuncdesc
    {
    long invId = spfuncdesc->invkind;
    // This is the Function Description of the required method.
    if invId == INVOKE_FUNC
    invId == INVOKE_PROPERTYPUT
    invId == INVOKE_PROPERTYPUTREF
    invId == INVOKE_PROPERTYGET
    {

    // Get parameters names
    CBSTRVector Names50;
    UINT nNames0;
    myDispatchObjectTypeInfo->GetNamesspfuncdesc->memid, &Names, 50, &nNames;
    nNames = __minnNames, UINTspfuncdesc->cParams + 1;
    if nNames < 1
    continue;
    OutputDebugStringWL"\r\n";
    OutputDebugStringW*Names;
    }
    }
    }
    }
    }
    }
    }


    into output I get com members like:

    AddRef

    QueryInterface

    and so on...


    Can you please help me with this?

    Thank you.

    :)
     
    Claudiu_D, Jan 16, 2020
    #1
  2. Kreij Win User

    Good book/site for C?

    The reason I suggest starting with C++ is that in my experience helping people learn to code, they have a harder time transitioning from a functional language (C) to an object oriented language (C++) than they do if they learn OOP first and wish to go back to functional coding (for whatever reason).

    C++ is a superset of C, although not neccessarily a 100% strict one.
    You can read the C++ Wiki for information on compatibility and differences between the two.

    Anyway, regardless of what you chose, the most important thing is to get going !!
     
    Kreij, Jan 16, 2020
    #2
  3. No O/C at all

    Now with the cpu step up O/C it averages around 55-58c on all cores.
     
    gerrynicol, Jan 16, 2020
    #3
  4. W1zzard Win User

    Cannot marshal from C# IReflect object to C++ IDispatch

    Learning to Program C

    my suggestion is to learn c first, then expand to c++ or java depending on your project requirements. if you decide to use visual studio (which i strongestly recommend) then you can just create c++ projects and write normal c code
     
    W1zzard, Jan 16, 2020
    #4
Thema:

Cannot marshal from C# IReflect object to C++ IDispatch

Loading...
  1. Cannot marshal from C# IReflect object to C++ IDispatch - Similar Threads - Cannot marshal IReflect

  2. Cannot Extend C drive

    in Windows 10 Gaming
    Cannot Extend C drive: im trying to extend the C drive but they extend button is greyed out. Below is the configuration i have on the server running server 2012 R2. Can you please help in any way ....
  3. Cannot Extend C drive

    in Windows 10 Software and Apps
    Cannot Extend C drive: im trying to extend the C drive but they extend button is greyed out. Below is the configuration i have on the server running server 2012 R2. Can you please help in any way ....
  4. Cannot delete C:/Mount

    in Windows 10 Network and Sharing
    Cannot delete C:/Mount: Cannot delete "C:/Mount" - 2.26 GB - Owner administrators, Guess Iam not an admin anymore https://answers.microsoft.com/en-us/windows/forum/all/cannot-delete-cmount/cc504090-5d69-4818-94ab-3234ba503161
  5. Cannot copy files from C drive to D because C drive is full?

    in Windows 10 Network and Sharing
    Cannot copy files from C drive to D because C drive is full?: My C drive is almost full 5.08 GB free of 221 GB so I want to move some files to my D drive 88 GB free of 931When I try to copy files from my C drive to the D I get an error message that says There is not enough space on OneDrive. You need an additional 28.1 GB free to copy...
  6. CANNOT CREATE NEW PARTITION FROM C DRIVE

    in Windows 10 Network and Sharing
    CANNOT CREATE NEW PARTITION FROM C DRIVE: I've created partitions on other computers for years and never had this message come up. I don't want to click on yes unless I know what it's about.[ATTACH]...
  7. C:\WindowsApp cannot be removed.

    in Windows 10 Network and Sharing
    C:\WindowsApp cannot be removed.: We were changing our boot drive and now our secondary drive is our boot drive, the issue is there is a windowsapp folder that is taking up 112 gigabytes on the computer, and the computer is saying “cannot find c:\windowsapps” and whatnot. I’ve tried to change permissions on...
  8. C&C callback from svchost.exe

    in Windows 10 Customization
    C&C callback from svchost.exe: Hello im keep getting C&C callback events on our devices to111.221.29.254:443which is Microsoft corp SingaporeISP located on Hong Kong. can you explain why microsoft's svchost.exe making this callback event. thank you....
  9. I cannot delete a user from C:/Users

    in Windows 10 Network and Sharing
    I cannot delete a user from C:/Users: I have deleted the user from my computer, but still the folder remains under C:/Users and contains appdata with A LOT of storage being taken up from it. I am using an administrator account and have control over the folder. When I try to rmdir del in CMD access is denied....
  10. CANNOT FIND C/C++ EXTENSION ON VISUAL STUDIO

    in Microsoft Windows 10 Store
    CANNOT FIND C/C++ EXTENSION ON VISUAL STUDIO: [ATTACH]i have tried a various keyword to in the search but I coudnt find c/c++ extension on VISUAL STUDIO helppppp pleassseeeeee https://answers.microsoft.com/en-us/windows/forum/all/cannot-find-cc-extension-on-visual-studio/ee42f381-ccd8-4c99-ab5f-da51162e2a35"