473,387 Members | 1,621 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

IDispatch definition in C#

Hello,

I am implementing a class in C# that wraps an automation server and am
stuck on something basic. Using the following code fragment:

using System;
using System.Runtime.InteropServices;

namespace ANamespace
{
public class Wrapper
{
private IDispatch* m_Server;

public Wrapper()
{};
}
}

the compiler complains

Wrapper.cs(70): The type or namespace name 'IDispatch' could not be found
(are you missing a using directive or an assembly reference?)

I suspect I am missing something, but I don't know from where to pull the
IDispatch definition in.

Any help is appreciated.

Phil Coveney
Nov 17 '05 #1
4 5379
> I suspect I am missing something, but I don't know from where to pull the
IDispatch definition in.


Why do you need it? Why not simply

private object m_Server;
Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 17 '05 #2
Mattias,
Why do you need it? Why not simply
private object m_Server; Fair enough. In fact, that's what I have been doing to make progress on
this project while I am resolving this. And, if this is Microft's intention
for C# developers, I guess that's what I'll do.

But two things trouble me about this.
First, (I think) it implies that I store all standard COM interface
references in object variables. It seems to me unnecessarily hiding
information about the variable's type. One could extend this logic, I
suppose, and note that I could store integer values in object variables,
which I think we can agree would not be good practice.
Second, since I can store references to .NET interfaces, this (I think)
implies I would develop my class distinguishing between standard COM
interfaces, and typelib-imported + non-COM iterfaces. If I change the
provider of a COM interface service from a COM to a non-COM service, does it
mean I change how I store the reference?

OK, I'm not trying to start a deep philosophy discussion. It just seems
strange that Microsoft would thoughtfully prevent the definition of its core
interfaces from being visible to .NET class designers. I am just trying to
understand its rationale.

Thanks for your help,

Phil Coveney

Nov 17 '05 #3
Phil,
t seems to me unnecessarily hiding
information about the variable's type.
Unless you're going to use any type specific functionality (ie
IDispatch methods) I don't see that as a problem.

OK, I'm not trying to start a deep philosophy discussion. It just seems
strange that Microsoft would thoughtfully prevent the definition of its core
interfaces from being visible to .NET class designers.


They don't prevent it, you can declare and use IDispatch if you really
have a reason to. If you do, the field declaration becomes

private IDispatch m_Server;

(not IDispatch*).
Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 17 '05 #4
OK, thanks Mattias.

Nov 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Peter Sparago | last post by:
I am working with the MSHTML editor control. I used win32com.client.gencache.EnsureModule on the MSHTML type library to generate the necessary IDispatch support for all the various interfaces used...
3
by: Roger That | last post by:
Hi, I am trying to use the function "CreateStreamOnHGlobal" from python code (I need to pass an IStream object to MSXML, like I do in C++ code). I was able to retrieve a pointer on the IStream...
0
by: | last post by:
well, how can i convert these code to VB.NET? thx CallJScript(const CString strFunc, const CStringArray& paramArray) { CComPtr<IHTMLDocument2> m_spDoc; m_spDoc.Attach(...
5
by: Dominic Godin | last post by:
Hi, I have decleared the IDispatch interface but I'm having trouble using it. Word.Application MSWord = new Word.ApplicationClass(); IDispatch wb = (IDispatch)MSWord.WordBasic; int lcid =...
1
by: Dmitry Medvedev | last post by:
Hello, I need to write C# class, that would implement IDispatch interface to be used in ActiveScript. I can't use IReflect interface here due to design issues, I need to handle GetIDsOfNames...
8
by: Charles Law | last post by:
Hi guys There's nothing much going on in Interop at the moment, so I'll post this here as well in case someone can give me a quick answer. The following is an extract from MSDN: <extract>...
0
by: Jim Hubbard | last post by:
How would I implement the IDispatch interface to handle the following in VB.Net <BEGIN> Controlling Download and Execution The WebBrowser Control gives you control over what it downloads,...
4
by: eselk | last post by:
I've got an out-of-process COM server (EXE) that I want to be able to control from Visual Basic. I can already control it from a C/C++ app without any issues. Under VBA in MS Access 2000, which I...
3
by: Huayang Xia | last post by:
I am trying to use ctypes to call dll functions. One of the functions requires argument "struct IDispatch* ". I do have a PyIDispatch object in python. How can I convert this "PyIDispatch object"...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.