Experts, I want to implement some COM interfaces in C#, and these interface will be called by a DLL written by ATL. The COM interface definations are : __interface IDataRelation : IUnknown { ... HRESULT GetData( [in] long Item, [in] REFIID riid, [out, iid_is(riid), retval] void **Data); } __interface IArray : IUnknown { ... } __interface INumber : IArray { .... HRESULT GetUnits([out, retval] BSTR *Units); } __interface IDoubleNumber : INumber { ... } The native code will call IDataRelation.GetData() to get the pointer of INumber to get the data unit. I rewrite the interfaces in C# [ComImport, Guid(XXX), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] public interface IArray {...} [ComImport, Guid(XXX), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] public interface INumber : IArray { ... [Return : MarshalAs(UnmanagedType.BSTR)] string GetUnit(); } [ComImport, Guid(XXX), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] public interface IDoubleNumber : INumber {...} [ComImport, Guid(XXX), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] public interface IDataRelation { [Return : MarshalAs(UnmanagedType.Interface)] object GetData( [In, MarshalAs(UnmanagedType.I4)] int Item, [In, MarshalAs(UnmanagedType.Struct)] ref Guid riid); } Then I construct two classes to implement these interfaces. public class ArrayBase : IArray, INumber, IDoubleNumber { string INumber.GetUnit() { return m_Unit; } } public class Data : ArrayBase, IDataRelatin { ... public object GetData(int Item, ref Guid riid); { return this; } } Every thing seems fine, IDataRelation can be retrived in the C++ code. CComQIPtr pRelation = GetDataRelation(...); //Get data relation if(pRelation != NULL) { CComQIPtr testNumber; pRelation->GetData(0, UUIDOF(INumber), reinterpret_cast( &testNumber )); if(testNumber != NULL) { CComBSTR m_DataUnit; testNumber->GetUnit(&m_DataUnit); //Error !!! } } When I call GetUnit, a strange error occured, see the following detail : Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call. This is usually a result of calling a function declared with one calling convention with a function pointer declar
G Richard
Posts
-
A question in Implement COM interface in C# [modified] -
can I export Template class in DLL?Is anybody knows? c++ : my dream
-
exe com server problem?Right it is out of process, but it is not single instance. The server is started first and can run serveral instance, which one is for a purpose. c++ : my dream
-
exe com server problem?I have write a exe com server. It can run more than one instance. When my client exe call createinstance, it always connect to the first started one, but i want my client exe to popup a dialog to choose one to connect. Is Any body konw how to it? thanks! c++ : my dream
-
CMDIChildWnd size problem in DOC/View OCXI want to migrate a MFC doc/view application to an activex control. I create the CMainFrame(inherited from CMDIFrameWnd) object when the activeX control is Created. but when i open a document, access violation occured in user.dll and no source code. i found the error is from CMDIChildFrame::OnSize. the following is my code : BOOL CMultiDocOCXCtrl::CreateMDIFrame() { if(m_pFrameWnd != NULL) return FALSE; CRect rc; GetClientRect(&rc); CMultiDocTemplate* pDocTemplate = new CMultiDocTemplate( IDR_MAINFRAME, RUNTIME_CLASS(CMyDocument), RUNTIME_CLASS(CChildFrame), RUNTIME_CLASS(CMyView)); AfxGetApp()->AddDocTemplate(pDocTemplate); // CString sClassName = AfxRegisterWndClass(CS_DBLCLKS); CMainFrame * pFrame = new CMainFrame; if(!pFrame->Create(sClassName, NULL, WS_CHILD|WS_VISIBLE, rc, this, MAKEINTRESOURCE(IDR_MAINFRAME), 0, NULL)) { delete pFrame; return FALSE; } pFrame->ShowWindow(SW_SHOW); pFrame->RecalcLayout(); // m_pFrameWnd = pFrame; // AfxGetApp()->m_pMainWnd = m_pFrameWnd; theApp.OnNewFile(); // return TRUE; } Is anybody know how this problem occur? c++ : my dream
-
a question in visual studio.net!thanks, let me see... c++ : my dream
-
a question in visual studio.net!how to modify the version info in the resource file, through vc7.net addin? I want to auto increase the build version when building. c++ : my dream
-
how to add a new toolbar to vs.net ide in the vs.net add-in?i have seen the samples in msdn, but all of them is written by vb.net. :omg: c++ : my dream
-
ScrollWindowEx Problem!I want to use the ScrollWindowEx to animate window, when scrolling. i mean I can't use ScrollwindowEx do the same thing that scrollwindow do, if i change the last parameter to SW_SMOOTHSCROLL. it can't update the region scrolled.why not have a try? you can test the following code inyou application. ... CRect rcClient; GetClientRect(&rcClient); ScrollwindowEx(100,0, &rcClient, &rcClient, NULL,NULL, SW_SMOOTHSCROLL); ... c++ : my dream
-
ScrollWindowEx Problem!does anyone knows how to use ScrollWindowEx? c++ : my dream
-
Fucntion pointer question!i declare a function pointer like this: void (*PTestFunc)(CString& str); and two classes: class CTest { ... void Test() { m_pTestFunc(CString("fdsaf")); } void SetFuncPointer(void* pointer) { m_pTestFunc = pointer; } PTestFunc m_pTestFunc; ... } class CMyClass { ... CString m_strCaption; void MyTest(CString& str); void Init(CTest& test); ... } CMyClass::MyTest(CString& str) { m_strCaption = str; } void CMyClass::Init(CTest& test) { test.SetFuncPointer((void*)MyTest); //error c2440 } ////////////////////////////// if i add "static" before MyTest, it is right; but u see i need this pointer in my class, i can't set MyTest static. so how to solve this problem? does c++ define the class member function pointer? :confused: c++ : my dream
-
Doese GDI+ provide the functions such as SetROP2 in GDI?can you explain it in more detail? the background in the client area is a bitmap, i draw my shape to the screen directly,too. but i don't know how to erase it. thanks to all the programmers who have helped me.
-
GDI+ question!how to draw a XOR line use GDI+:confused: thanks to all the programmers who have helped me.
-
Doese GDI+ provide the functions such as SetROP2 in GDI?draw a XOR line useing GDI+! thanks to all the programmers who have helped me.
-
Doese GDI+ provide the functions such as SetROP2 in GDI?I want to know how to use GDI+ to draw a rubber line? :-D Let's use GDI+ to draw! hoho
-
how to popup a dialog in a combobox like control?thanks, but I didn't find. Do u have any more suggestions?:confused: thanks to all the programmers who have helped me.
-
how to popup a dialog in a combobox like control?Not a modal dialog. Just like a list box in combobox!:eek: thanks to all the programmers who have helped me.
-
how to popup a dialog in a combobox like control?I want to make a combobox control that popup a dialog. I put my control on a dialog named dialog1 and popup dialog2. I found dialog1's title bar become inactive. but when combobox popup listbox, the dialog dosen't become inactive. Is anyone can help me?:confused: :confused: thanks to all the programmers who have helped me.
-
how to control the controls in the dialogs of the word?to be simple, I want to create a word document with my own format. And I will provide some dialogs to let people coustomize the format. so have to use some word's automation interface. But when a dialog of word do modaled, I can't get the status untile the dialog ended. for example, in the dialog "insert -> index and content" there are some check boxes, and i want to set the check boxes' status in my code. what can I do? thanks to all the programmers who have helped me.
-
how to control the controls in the dialogs of the word?right! But when the dialogs of the word show modal, I can't use the interfaces, I have to waiting for the user to select an item. How can I do it automaticly? thanks to all the programmers who have helped me.