|
AnanyaMohan wrote: I have an interface object say IMarkSet. I passed to an COM function. There i need to access a function which takes CMarkedSet .
^
|
v
How to convert interface object to its class?
The answer is really simple: you don't.
The reason may be a bit more complicated....
This is a design flaw either in your class or the interfaces it exposes and perhaps even a combination. This is all about abstraction and encapsulation.
A COM object/server exposes several interfaces that can be used to alter the behaviour and/or state of the server. Whatever the server is supposed to do, it must be possible to trigger it through the interfaces. Perhaps you need to query for another interface, or even implement an additional interface, but that's all right; it's supposed to work that way.
But how the server accomplishes its task is entirely up to the server and is encapsulated behind interfaces.
In short: you have to re-evaluate your design.
"It's supposed to be hard, otherwise anybody could do it!" - selfquote "High speed never compensates for wrong direction!" - unknown
|
|
|
|
|
AnanyaMohan wrote: There i need to access a function which takes CMarkedSet
That simply is wrong thing, you are trying to do. Always talk through interface.
|
|
|
|
|
Hi,
Iam using a c++ dll in my .net application.It is running fine on the system where visual studio 2005 is installled.
In the deployment environment we have only framework2.0 installed on the machine.Then Iam getting a pop-up error as
"<big><b>Microsoft visual c++ runtime library
Runtime error
c:\testapp\bin\debug\test.exe
The application has requested the application to terminate in the unusual way
Please contact the application's support team for more information</b></big>"
Please kindly help ASAP
|
|
|
|
|
One thing you can look at to troubleshoot this issue...use depends.exe to see what dependencies you have in your dll. If you suspect it might be the framework, perhaps look at the runtime libraries like MSVCR80.dll to see what versions are on your dev system vs your deployment system.
Also, you didn't really provide much information, so I'm not sure if anyone can really provide much feedback.
|
|
|
|
|
My application working fine in the dev environment.But in the testing /production environment
it is not working because that environment has only
windows server 2003
IIS
.net2.0 framework
In my application I have Used some microsoft VC++ dll's also along with .net dll's.
Now Iam getting "RUNTime Error" pop-up screen message as below
" The Application has been terminated in an Unusual Way"
On googling i came to know that some dll's like msvcrt.dll of windows server 2003 has to be changed...But Iam not pretty sure about it..
In Production/test environment there is only framework installed ,but there is no visual studio installed on it.may be due that this error may occur...
So kindly post your suggestions and views to help me
I tried the following as suggested by you:
1. I have installled the redistributable package suggested by you.
after installing i restarted the PC even now also I got the same runtime pop-up error.
2. Then I checked even with the dependency walker for the dll.
I found that there is no miising dll.
3. Then I tried by installing Visual C++ express edition..even then also i got the same pop-up error.
Kindly help me.....
|
|
|
|
|
Hello there,
I've made ActiveX control which is used in my webpage to get client's system information.
I followed the article http://www.codeproject.com/KB/COM/CompleteActiveX.aspx[^] to create and sign the control.
In short I followed this steps:
1. the control is created and is marked as safe
2. The control is packaged into the cab file
3. The cab file is signed by class3 digital certificate issued by Thawte
4. The control is now embedded into the web-page.
The command used for creating cab file and signing it are
c:\cabsdk\bin\cabarc -s 6144 N SystemCheck.cab SystemCheck.ocx SystemCheck.inf
signcode -n "SystemCheck" -i http:
Now when I run the control it runs from most of the machines but from some machines it gives "Unknown publisher" Error.
The page is hosted online and is available at http://92.61.60.4/vod/SystemCheck1.htm[^]
Please note that it doesn't give unknown publisher error on all machines.
Thanks in advance...
|
|
|
|
|
Well, I have a question about the usuage of CComPtr, but I think I know the answer, but would like to make sure I understand this completely...
CComPtr is a smart pointer class for managing COM interface pointers, thus I don't need to worry about calling AddRef for Release methods, since they are automatically called. From what I've read, the Release method will be called when the CComPtr goes out of scope.
I'm have the task of maintaining a COM client app (first time with COM) and I was thinking about 'reusing' a particular instance of a CComPtr (no need to declare a new one, since there's one already!) The only thing that had me worried what that by reusing the CComPtr does that screw up the reference counting and create a memory leak... psuedocode below:
{
CComPtr<isomething> myIsomething = (some Isomething interface)
...do stuff to the CComPtr...
...lets reuse it...
myIsomething = (some other Isomething interface)
}
Since the myIsomething didn't go out of scope when I set "myIsomething" to another interface, I was worried that it may be an issue. So after a day of digging around this is my conclusion:
This is actually OK, since if we look at the definition of this template, the = operator is overloaded as such:
T* operator=(T* lp) {
return (T*)AtlComPtrAssign((IUnknown**)&p, lp);
}
When I looked up AtlComPtrAssign, it seems that it will call release on the interface pointer, prior to reassignment to the new interface. If that's true, there shouldn't be any issues with reference counting and I can continue on my merry way?
|
|
|
|
|
Hello alchong,
>>...lets reuse it...
>>myIsomething = (some other Isomething interface)
Yes, this is OK AFAIK. One reusage problem that I have encountered before is related to QueryInterface().
If you were to do this :
ISomething -> QueryInterface(IID_ISomething, (void**)&myIsomething);
you will get an assertion failure if myIsomething is already holding onto another interface pointer.
You can overcome reusage problems by first assigning myIsomething to NULL as in :
myIsomething = NULL;
before reusing it.
- Bio.
|
|
|
|
|
I see, by assigning it to NULL, that forces the release on the currently held interface, correct? Thanks for the extra tip!
|
|
|
|
|
Hello, i'm created installation project and during installing process i need to config Component Services -> Computers- >My Computer->Dcom Config security properties.
In particular...Security - >Launch Permission : Add ASPNET user and give him rights to Activation/Launch.
I'm know how to do this manually, but how do this on programly on C#?
Thank's and sorry for my english.)))
|
|
|
|
|
I have a VC++ generated COM executable that I wish to launch under a different user to the launching process, i.e. the interactive user.
I have found that this can normally be set in DCOMCNFG, under the identity tab of the properties for the particular application.
All other programs listed in DCOMCNFG have an application type of ‘local server’ and display the ‘Identity’ tab but my program has an ‘application type’ of ‘Remote server’ and the properties of my program do not include this tab.
I have tried adding the 'RunAs' registry entry manually to no effect.
Can anyone tell me why my program is listed as a ‘remote server’ rather than a ‘local server', or what else I should be doing.
Inside the program uses the wizard generated code:
_AtlModule.RegisterClassObjects(CLSCTX_LOCAL_SERVER, REGCLS_MULTIPLEUSE)
_AtlModule.RegisterServer(TRUE)
Thanks
Steve.
|
|
|
|
|
For anyone who might be interested I found the problem...
When the server was registered the AppId field of the CLSID was not set.
As a permanent solution I changed the .rgs file that sets this value from using a parameter to using the explicit value.
NoRemove CLSID
{
ForceRemove....
{
ProgID
.
val AppID = s '%APPID%'
val AppID = s {XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}
}
}
|
|
|
|
|
Hello!
I am working on a C# COM-Server and a C++ COM client app. The client in fact
loads a dll-plugin containing the COM client in a class that acts as a com
event reciever:
extern "C"
__declspec(dllexport)
int ndofInit();
extern "C"
__declspec(dllexport)
void* ndofOpen(void* wnd);
extern "C"
__declspec(dllexport)
void ndofShutdown(void* deviceHandle);
[ event_receiver(com) ]
[ module(type=dll, name="NDOF") ]
class NDOFServer
{
public:
NDOFServer() {}
virtual ~NDOFServer();
...
}
Everytime I start the client I get the following error:
Debug Assertion failed!
Program ...
File: C:\Programme\Microsoft Visual Studio 8\VC\atlmfc\include\atlbase.h
Line 2706
Expression _pAtlModule == 0
Clicking Retry and returning to my code reveals that this error occurs when
the constructor of NDOFServer() is called.
The constructor is called this way by the client app:
extern "C"
__declspec(dllexport)
int ndofInit()
{
if (sNdofServer == NULL)
sNdofServer = new NDOFServer();
return 1;
}
This error seems not to occur when the client plugin-DLL is used with
another COM server offering the same classes etc. written in C++ (whose code
I do not know).
I tried to switch some more or less relevant options in the project
properties like:
- MFC usage static/shared/Windows shared
- ATL usage static/shared/none
- minimize CRT usage in ATL yes/no
- CLR support no/CLR
stdafx.h looks like this:
#if defined(_WIN32)
#ifndef WINVER // Allow use of features specific to #define WINVER
0x0501 // Change this to to target other
#endif
#ifndef _WIN32_WINNT // Allow use of features specific to
#define _WIN32_WINNT 0x0501 // (was 0x0501) Change to target other versions
#endif
#ifndef _WIN32_WINDOWS // Allow use of features specific to
#define _WIN32_WINDOWS 0x0410 // Change this to target Windows Me or later.
#endif
#ifndef _WIN32_IE // Allow use of features specific to IE
#define _WIN32_IE 0x0600 // Change this to target other versions of IE.
#endif
#define _ATL_APARTMENT_THREADED
#define _ATL_NO_AUTOMATIC_NAMESPACE
#define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS
#include <atlbase.h>
#include <atlcom.h>
<---->
//#include <atlwin.h>
//#include <atltypes.h>
//#include <atlctl.h>
//#include <atlhost.h>
--> commenting these headers out did neither help nor hurt
using namespace ATL;
#import "progid:AerionInput.Device" embedded_idl no_namespace
#endif //_WIN32
The C# DLL is nothing spectacular and the "main" class(or the first one
being instanciated), which is not instanciated at this time. The COM-visible
interface looks like this:
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
namespace AerionInput
{
[
Guid("CB3BF65E-0816-482A-BB11-64AF1E837812"),
InterfaceType(ComInterfaceType.InterfaceIsDual)
]
public interface ISimpleDevice
{
int Type
{
get;
}
IKeyboard Keyboard
{
get;
}
ISensor Sensor
{
get;
}
void Connect();
void Disconnect();
void LoadPreferences(string preferencesName);
}
}
And the AssemblyInfo.cs reads this like:
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
[assembly: AssemblyTitle("TDxInput")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("n/a")]
[assembly: AssemblyProduct("TDxInput")]
[assembly: AssemblyCopyright("Copyright © n/a 2008")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: ComVisible(true)]
[assembly: Guid("7858b9e0-5793-4be4-9b53-661d922790d2")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
I am doing this on Windows 2000 with Visual Studio 2005 Pro latest SP and
.NET 2.0.50727 SP1.
Thanks in advance,
Christian
|
|
|
|
|
I have a VB.Net COM dll that I created and installed (using regasm) on a server. On this server is an application that calls different code modules based on events. One of those code modules calls the com dll which fires off and does a few things. If this process is kicked off from the server, everything works just fine. However, when the application is run from a workstation, the COM call fails. The workstation calls the code modules that reside on the server, the same ones that the server uses.
So why would the call to the COM object work fine on the Server, but when called through a workstation, to the server, fails out?
The CreateObject statement that creates the com object does not fail, but when called through the workstation, the call to the COM method fails.
Here's an example:
foo = CreateObject("Obj.Class")
result = foo.callMethod
The CreateObject works fine, but the foo.callMethod fails when it is kicked off from a workstation.
Anyone run into something like this before?
|
|
|
|
|
I would like to use the DECLSPEC_UUID and __uuidof operators to identify my record types.
In the IDLs I use constructs like:
typedef
[ uuid(....)
, version(1.0)] struct x {
...
} x;
Ok now MIDL creates in the header:
typedef DECLSPEC_UUID(....) struct x {
...
} x;
But the call of __uuidof(x) is invalid, as the order of DECLSPEC_UUID and struct has to be switched. So why does MIDL create this unusable code??
One possible solution is dropping typedef, but in each sample idl I saw before they allways used typedef with structures. Furthermore it is not possible to use the version-tag without the typedef.
Any Ideas??
|
|
|
|
|
How do I pass MySQL connection ID to COM using VC++ 9.0?
At the moment I have to pass the host, username, pwd, and db name to the COM but make a new connnection there. I want to pass the connection ID but I am unable to shoehorn a variable of type MYSQL into an acceptable parameter.
GER
Ger
|
|
|
|
|
Hi,
I have a VS 6.0 (visual basic) add-in for Outlook that I wrote for Outlook 2002 (XP). It is a useful add in that I wish (or maybe not, LOL) to modify to support Outlook 2003 & 2007. I have Visual Studio 2008 Pro installed along with Office 2003.
Using the VSTO add-in templates, I wanted to create a simple 'Hello' add-in and ensure that it works and then test it on a client install (a machine not running any development tools). At first I thought this would be easy, but find my asking Why is it so difficult to create a simple add-in and have it work.
The built-in VSTO addin templates seem to force .NET, which has many pre-requisites and all kinds of stuff.
My first question to the Code Project World, <u>is it better to use templates or create Addin using C++ and COM without .NET? </u>
I did write a simple 'Hello' using C++/COM without .NET, which produces a <i>Clean</i> .dll that registers as add-in. Where the .NET solution has manifest and .NET security policy assembly difficulties. Plus .NET is not required and do not want to force clients to install All this extra Baggage for what should be a simple addin.
Thanks to code found here on CodeProject, I was able to get this far, but am at a crossroad now. I appreciate any comments from the experts.
Aloha, Mike
|
|
|
|
|
Hi,
I am using CLSID_MMDeviceEnumerator for creating the instance of MMDeviceEnumerator.However,the call CoCreateInstance is failing saying the class is not registered.Upon checking the CLSIDs in the registry,i found that its not there in registry.
What to do?
The below code is taken from MSDN.
// soundcard.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include<atlbase.h>
//#include "Winerror.h"
#include "Mmdeviceapi.h"
#include "Functiondiscoverykeys_devpkey.h"
//-----------------------------------------------------------
// This function enumerates all active (plugged in) audio
// rendering endpoint devices. It prints the friendly name
// and endpoint ID string of each endpoint device.
//-----------------------------------------------------------
#define EXIT_ON_ERROR(hres) \
if (FAILED(hres)) { goto Exit; }
#define SAFE_RELEASE(punk) \
if ((punk) != NULL) \
{ (punk)->Release(); (punk) = NULL; }
const CLSID CLSID_MMDeviceEnumerator = __uuidof(MMDeviceEnumerator);
const IID IID_IMMDeviceEnumerator = __uuidof(IMMDeviceEnumerator);
void PrintEndpointNames()
{
HRESULT hr = S_OK;
IMMDeviceEnumerator *pEnumerator = NULL;
IMMDeviceCollection *pCollection = NULL;
IMMDevice *pEndpoint = NULL;
IPropertyStore *pProps = NULL;
LPWSTR pwszID = NULL;
hr = CoCreateInstance(
CLSID_MMDeviceEnumerator, NULL,
CLSCTX_INPROC_SERVER, IID_IMMDeviceEnumerator,
(void**)&pEnumerator);
EXIT_ON_ERROR(hr)
hr = pEnumerator->EnumAudioEndpoints(
eRender, DEVICE_STATE_ACTIVE,
&pCollection);
EXIT_ON_ERROR(hr)
UINT count;
hr = pCollection->GetCount(&count);
EXIT_ON_ERROR(hr)
if (count == 0)
{
printf("No endpoints found.\n");
}
// Each loop prints the name of an endpoint device.
for (ULONG i = 0; i < count; i++)
{
// Get pointer to endpoint number i.
hr = pCollection->Item(i, &pEndpoint);
EXIT_ON_ERROR(hr)
// Get the endpoint ID string.
hr = pEndpoint->GetId(&pwszID);
EXIT_ON_ERROR(hr)
hr = pEndpoint->OpenPropertyStore(
STGM_READ, &pProps);
EXIT_ON_ERROR(hr)
PROPVARIANT varName;
// Initialize container for property value.
PropVariantInit(&varName);
// Get the endpoint's friendly-name property.
hr = pProps->GetValue(
PKEY_Device_FriendlyName, &varName);
EXIT_ON_ERROR(hr)
// Print endpoint friendly name and endpoint ID.
printf("Endpoint %d: \"%S\" (%S)\n",
i, varName.pwszVal, pwszID);
CoTaskMemFree(pwszID);
pwszID = NULL;
PropVariantClear(&varName);
SAFE_RELEASE(pProps)
SAFE_RELEASE(pEndpoint)
}
SAFE_RELEASE(pEnumerator)
SAFE_RELEASE(pCollection)
return;
Exit:
printf("Error!\n");
CoTaskMemFree(pwszID);
SAFE_RELEASE(pEnumerator)
SAFE_RELEASE(pCollection)
SAFE_RELEASE(pEndpoint)
SAFE_RELEASE(pProps)
}
int _tmain(int argc, _TCHAR* argv[])
{ HRESULT hr=CoInitialize(NULL);
PrintEndpointNames();
::CoUninitialize();
return 0;
}
|
|
|
|
|
Hello,
I am trying to find some examples and information on how to add COM to the C# application and connect to a COM server that was created with C++. Any help would be wonderful.
Thanks
|
|
|
|
|
|
Hello.
I was wondering if it is possible to get a COM pointer to a running instance of Yahoo Messenger.
I have tried several methods but got stuck due to the fact that I am kind of a noob when it comes to COM.
The best I managed is to create a instance of Yahoo! Messenger via COM from my app.
In order to run multiple instances of Yahoo! Messenger you need to set<br />
[HKEY_CURRENT_USER\Software\yahoo\pager\Test]<br />
"Plural"=dword:00000001
I apologize if my question is with obvious answer/stupid/dumb.
Thanks in advance.
|
|
|
|
|
Hi,
I need to pass MFC Class "CStringArray" as Parameter in my exposed method in com component.
When I Compile I get 2 errors
1)#error MFC requires C++ compilation (use a .cpp suffix)
2)command line error MIDL1003 : error returned by the C preprocessor (2)midl
Can Anybody suggest me how to go about it?
Thanks
Satya
Today is a gift, that's why it is called the present.
|
|
|
|
|
Hi,
I m using OWC11 with ASP, Trying to draw simple Bar graph using data from SQL database, i managed to draw the chart but i also have an extra chart(to the right) with it. Please let me know how to get rid of it.
here is the piece of code that does the charting
Set objRS1 = Server.CreateObject("ADODB.Recordset")
objRS1.Open strSQLStatement, objADODB, 1
'Response.Write("The value of " & strColName & "=" & objRS1(0))
set objCSpace = Server.CreateObject("OWC11.ChartSpace")
'set up chart and properties
set objChart = objCSpace.Charts.Add(0)
set objConstants = objCSpace.Constants
'create a clustered column chart
objChart.Type = objConstants.chChartTypeColumn3D
'add a legend
objChart.HasLegend = False
'objChart.ShowFilterHeaders = False
set objCSpace.DataSource = objRS1
objCSpace.HasMultipleCharts = False
objCSpace.HasChartSpaceLegend = False
objCSpace.HasChartSpaceTitle = False
objCSpace.DisplayFieldButtons = false
objCSpace.MinorVersion =
'set the data points and categories
'objChart.SetData objConstants.chDimSeriesNames, 0, "age"
objChart.SetData objConstants.chDimCategories, 0, "Level"
objChart.SetData objConstants.chDimValues, 0, "NOF"
'set up some additional properties
'add and format the chart title
objChart.HasTitle = True
objChart.Title.Caption = "TICS Summary"
set objFont = objChart.Title.Font
objFont.Name = "Tahoma"
objFont.Size = 10
objFont.Bold = True
'add and format a title to the category axis
set objAxis = objChart.Axes(objConstants.chAxisPositionBottom)
objAxis.HasTitle = True
objAxis.Title.Caption = "TICS Levels"
set objFont = objAxis.Title.Font
objFont.Name = "Tahoma"
objFont.Size = 8
objFont.Bold = True
'add and format a title to the value axis
set objAxis = objChart.Axes(objConstants.chAxisPositionLeft)
objAxis.HasTitle = True
objAxis.Title.Caption = "No. Of Files"
set objFont = objAxis.Title.Font
objFont.Name = "Tahoma"
objFont.Size = 8
objFont.Bold = True
'Save the current chart to a GIF file with a temporary
'filename using the FSO
set fso = Server.CreateObject("Scripting.FileSystemObject")
strFileName = fso.GetTempName()
GifFileName = strFileName
strFileName = Server.MapPath(".") & "\" & strFileName
RenName = strFileName
RenName = replace (RenName, ".tmp", ".gif")
'Response.Write(GifFileName)
GifFileName = replace (GifFileName, ".tmp", ".gif")
objCSpace.ExportPicture RenName, "gif", 800, 400
'fso.MoveFile strFileName,GifFileName
Response.Write("<img src=" & GifFileName & ">")
'Use On Error Resume Next to make sure we eventually delete
'the temporary GIF file even if something fails in the next
'couple of functions
on error resume next
'The GIF file has been created. Return the contents of the
'GIF file as binary data using the BinaryFileStream COM object
set objBinaryFile = Server.CreateObject("BinaryFileStream.Object")
Response.BinaryWrite objBinaryFile.GetFileBytes(CStr(strFileName))
'Delete the GIF file since it is no longer needed
objBinaryFile.DeleteFile CStr(RenName)
'clear variables
set objBinaryFile = nothing
set FSO = nothing
set objCSpace = nothing
</img>
Please Help!!!
|
|
|
|
|
Hello!
My name is Alla. I'w working as a programmer in New Hampshire. I've just started doing Word and Powerpoint Automation (never done before Office Automation). The application I'm working on now creates document-packages,containing one or more Word documents and export these documents to particular locations.
I created Word Application Instance only once at the beginning, so I use this Instance for all documents that I'm going to create for exporting. Everything was fine so far, but when I'm trying to export a huge amount of documents,the following error appears - RPC SERVER UNAVAILABLE and any reference to existing Word Instance throws an error ( it happens when during processing some documents for some reason Range.Paste method throws an exception (RPC server failed)., then I get MS Word warning message and Word trying to recover documents. Immediately after that I get RPC SERVER UNAVAILABLE - means that any access to my Word Instance fails. May be it makes sense to create many Word Application Instances for each document, but we have problem with performance.I tried to send this question to microsoft forums, but nobody responded..Could you, please, help me to solve this problem?
Thank you very much in advance and best regards.
Alla
|
|
|
|
|
Hey How did you resolve this?
|
|
|
|
|