Click here to Skip to main content
15,886,518 members
Home / Discussions / C#
   

C#

 
GeneralRe: sealed classes Pin
Scott Dorman6-Sep-07 18:09
professionalScott Dorman6-Sep-07 18:09 
QuestionInsert character Pin
M Riaz Bashir5-Sep-07 23:14
M Riaz Bashir5-Sep-07 23:14 
AnswerRe: Insert character Pin
blackjack21505-Sep-07 23:22
blackjack21505-Sep-07 23:22 
AnswerRe: Insert character Pin
Revathij5-Sep-07 23:53
Revathij5-Sep-07 23:53 
QuestionPost-Build on Vista Pin
Russell Jones5-Sep-07 23:04
Russell Jones5-Sep-07 23:04 
AnswerRe: Post-Build on Vista Pin
mav.northwind6-Sep-07 0:37
mav.northwind6-Sep-07 0:37 
GeneralRe: Post-Build on Vista Pin
Russell Jones6-Sep-07 3:33
Russell Jones6-Sep-07 3:33 
QuestionA question in Implement COM interface in C# [modified] Pin
G.Richard5-Sep-07 22:52
G.Richard5-Sep-07 22:52 
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<idatarelation> pRelation = GetDataRelation(...); //Get data relation

if(pRelation != NULL)
{
CComQIPtr<inumber> testNumber;
pRelation->GetData(0, UUIDOF(INumber), reinterpret_cast<void**>( &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 declared with a different calling convention.

The ATL DLL is used to display a chart. I use it in my C# project. The above interfaces are its

data source interface. I just want to implement these interfaces to supply my own data source for

it. My project is not a COM server and not COM visible.

The ATL DLL is written years ago, but only used by other C++ projects and have no problem, I can't change anything.

I haved searched for the above error solution, but got nothing.

Now, Any idea?






-- modified at 5:01 Thursday 6th September, 2007

c++ : my dream

QuestionRichTextBox keyboard cursor Pin
mihksoft5-Sep-07 22:25
mihksoft5-Sep-07 22:25 
AnswerRe: RichTextBox keyboard cursor Pin
mav.northwind6-Sep-07 0:30
mav.northwind6-Sep-07 0:30 
QuestionModal Windows in smart parts Pin
umashankergr85-Sep-07 21:29
umashankergr85-Sep-07 21:29 
QuestionOLEDB problem Pin
sulabh20205-Sep-07 21:28
sulabh20205-Sep-07 21:28 
AnswerRe: OLEDB problem Pin
Pete O'Hanlon5-Sep-07 21:39
mvePete O'Hanlon5-Sep-07 21:39 
GeneralRe: OLEDB problem Pin
sulabh20205-Sep-07 21:42
sulabh20205-Sep-07 21:42 
QuestionWhy din't MS include Multile inheritance in C#? Pin
Blumen5-Sep-07 21:27
Blumen5-Sep-07 21:27 
AnswerRe: Why din't MS include Multile inheritance in C#? Pin
DavidNohejl5-Sep-07 21:47
DavidNohejl5-Sep-07 21:47 
AnswerRe: Why din't MS include Multile inheritance in C#? Pin
Pete O'Hanlon5-Sep-07 21:48
mvePete O'Hanlon5-Sep-07 21:48 
GeneralRe: Why din't MS include Multile inheritance in C#? Pin
J4amieC5-Sep-07 22:15
J4amieC5-Sep-07 22:15 
GeneralRe: Why din't MS include Multile inheritance in C#? Pin
Blumen5-Sep-07 23:34
Blumen5-Sep-07 23:34 
GeneralRe: Why din't MS include Multile inheritance in C#? Pin
J4amieC6-Sep-07 0:11
J4amieC6-Sep-07 0:11 
GeneralRe: Why din't MS include Multile inheritance in C#? Pin
Pete O'Hanlon6-Sep-07 0:22
mvePete O'Hanlon6-Sep-07 0:22 
GeneralRe: Why din't MS include Multile inheritance in C#? Pin
Luc Pattyn6-Sep-07 3:25
sitebuilderLuc Pattyn6-Sep-07 3:25 
GeneralRe: Why din't MS include Multile inheritance in C#? Pin
Blumen6-Sep-07 17:46
Blumen6-Sep-07 17:46 
GeneralRe: Why din't MS include Multile inheritance in C#? Pin
Rudolf Jan6-Sep-07 5:07
Rudolf Jan6-Sep-07 5:07 
GeneralRe: Why din't MS include Multile inheritance in C#? Pin
Blumen6-Sep-07 17:51
Blumen6-Sep-07 17:51 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.