The Wayback Machine - https://web.archive.org/web/20090418080856/http://www.codeproject.com:80/script/Forums/View.aspx?fid=1648
Click here to Skip to main content
6,077,753 members and growing! (14,956 online)
Announcements
* Bold indicates new messages since 23:08 17 Apr '09
BullFrog Power
 

COM


Home > Forums > COM

 Msgs 1 to 25 of 328 (Total in Forum: 10,289) (Refresh)FirstPrevNext
QuestionHow to get image from IHTMLImgElement ?memberalexhalt15hrs 54mins ago 
Hello!


There is interface IWebBrowser2, which I use to get IHTMLDocument2, IHTMLElementCollection, IHTMLElement, IHTMLImgElement from.
I can get different picture options from IHTMLImgElement, but I can't get the picture itself.
How can I do that? Please advise.

P.S.

I've tried to use the following code:

IOleCommandTarget* pCT;
CComVariant vGlyphTableEntry;
vGlyphTableEntry = "c:\\temp.jpg";

if (pElemDispatch->QueryInterface(__uuidof(IOleCommandTarget), (void**)&pCT)==S_OK)
{
pCT->Exec(&CGID_MSHTML, IDM_SAVEPICTURE , OLECMDEXECOPT_DONTPROMPTUSER ,&vGlyphTableEntry, 0);
pCT->Release();
}


But this code shows the 'Save as' dialog, which shouldn't appear. What's wrong with this code? Is there some other way to do that?

Thanks in advance
Questionhow to ping message in wireless networkmemberalish06104:04 15 Apr '09  
I want to write a program which checks present available wireless networks through my wireless application ,
and to ping message to all the networks to check their availability..... i think i have use aodv concept but dont no how to start .... pls help in getting start ...

Thanks for any suggestion ....
Questionerror "Missing file: ---- Urgentmembershantanusenin19:44 14 Apr '09  
I am trying open a excel file after downloading it from website, but its giving error "Missing file: C:\default.css?5".how can i overcome the error thru C#.
Thanks
Senz
QuestionRe: Call C# DLL using C++ - "Not enough storage is available to complete this operation" [modified]membermla1549:42 14 Apr '09  
Hello,
I want to create a C# DLL that passes out a string as a parameter.   I have tried this (partial code):

[C# Code]
public interface iInterface1
{
            [System.Runtime.InteropServices.DispId(13)]
            void Call13(
                  [System.Runtime.InteropServices.In]
                  [System.Runtime.InteropServices.Out]
                  [System.Runtime.InteropServices.MarshalAs(
                  System.Runtime.InteropServices.UnmanagedType.BStr)]
                  ref string s1);
            [System.Runtime.InteropServices.DispId(17)]
            void Call17(
                  [System.Runtime.InteropServices.In,
                  System.Runtime.InteropServices.Out,
                  System.Runtime.InteropServices.MarshalAs(
                  System.Runtime.InteropServices.UnmanagedType.LPWStr)]
                  ref System.String s1);
}

[C++ Code]
BSTR s;
m_int0.Call13(&s);

[C++ Code]
LPWSTR s2;
m_int0.Call17(&s2);

The programs compile, but do not run:
The C++ call to Call13 gives me the message "Not enough storage is available to complete this operation".
The C++ call to Call17 in Debug mode shows that there is a breakpoint in the program:
"This may be due to a corruption of the heap, and indicates a bug in go2.exe or any of the DLLs it has loaded."

Does anyone have any ideas?

Regards,
Mike
modified on Wednesday, April 15, 2009 10:23 AM
AnswerRe: Call C# DLL using C++ - "Not enough storage is available to complete this operation"membermla15411:55 15 Apr '09  
http://books.google.com/books?id=ZDin4axsYoEC&pg;=PA398&lpg;=PA398&dq;=call+managed+code+stringbuilder&source;=bl&ots;=x45eJ7Ns__&sig;=bGDq4U5_urIqdmvfqmLmWkXgaeY&hl;=en&ei;=uC_mSePgLYuwMqq27YwJ&sa;=X&oi;=book_result&ct;=result&resnum;=2#PPA374,M1[^]

Regards,
Mike

QuestionUnable to emit assembly: Referenced assembly 'Interop.ADODB' does not have a strong namememberMarcelloTurnbull7:37 14 Apr '09  
Hi

My VB.NET Library references ADODB. When I build it, the above message comes out.

Should I run tlbimp.exe ?

Thanks

Marcello Turnbull
AnswerRe: Unable to emit assembly: Referenced assembly 'Interop.ADODB' does not have a strong namemembermla1548:53 15 Apr '09  
You may need a strong name key file.   Investigate Project Properties->Signing:
Sign the assembly
Choose a strong name key file

Regards,
Mike
QuestionWriting a COM Server Explorer, similar to OLE/COM Object Viewer (but, not as cool)memberBaltoro15:10 13 Apr '09  
I currently am in the process of writing an application that locates information about COM class objects and server objects that are registered on my machine.
I began by enumerating the HKEY_CLASSES_ROOT\CLSID subkey, to get an idea how many COM components exist. This part of the application works fine, and provides basic data on all components with a CLSID.
I'm gradually expanding its capabilities, and what I'd like to do is enumerate all ActiveX controls registered on my computer. Naturally, I'd like a complete inventory, and I'm wondering what is the best way to determine if a COM component is an ActiveX control (in the most basic sense, that it can be instantiated from a Web Page). So, I've been reading: "Hacking Exposed Web 2.9: Security Secrets and Solutions", copyright 2008, McGraw-Hill. It describes clearly the existing problems with ActiveX controls and how Internet Explorer 7 deals with it. Here's some background:

"The ActiveX technology was introduced by Microsoft in the 1990s to allow developers to do more with their web applications. ActiveX is often used when a rich set of functionality is required on a Windows machine, such as patch installation (Windows Update), multimedia (Flash/WMP/QT), and document viewing (Acrobat). ActiveX control components are downloaded to user’s browser and/or operating system and integrates with a web application. Traditional web applications (Web 1.0) might require Win32 clients on the operating system (OS) for an ideal user experience; however, Web 2.0 trends involve clients running in the browser rather than the OS."
"ActiveX is a Component Object Model (COM) object. COM is used to enable interprocess communications (IPC) through various parts of the OS and its applications. COM also is used for intraprocess communication, meaning the control is loaded in-process. The latter is the most common usage scenario for ActiveX controls. COM is used with ActiveX primarily because it provides a common interface for interacting with arbitrary objects. ActiveX objects allows a program to self-register, add registry/file system entries, and automatically run. Essentially, COM objects allow methods and interfaces to be called from one application to another, without them having to know the ins and outs of the application itself."

The book goes on to describe the security problems with ActiveX controls in great detail. It makes interesting reading, especially if you are a Web developer.
In my research, I ran across a SourceForge site for an ActiveX/COM Enumerator and Fuzzer.
You can read through the source code at: ActiveX COM Enumerator and Fuzzer[^]
However, the principle technique of locating and disabling an ActiveX control depends entirely on whether the COM component implements the IObjectSafety interface. The code also searches for registry keys that be altered at this registry location: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\ActiveX Compatibility\CLSID of the ActiveX control. (explanation here: IObjectSafety and Internet Explorer[^]
Anyway, what I'd like to do is find a reliable technique for determining if a registered COM component is an ActiveX control and can be loaded into Internet Explorer.
Questionout process server crash.........membercontactjey7:11 13 Apr '09  
Hi all,

I am new to COM,

and i use MFC for developing com

I developed an out process server(Automation Server) and i exposed a singleton comobject to outside world

to achieve singleton what i have done is inherited a class from COleObjectFactory and override the OnCreateObject in the derived class and it looks like this

CCmdTarget* CSingletonFactory::OnCreateObject()
{
//static CServer m_sServer;
//return &m_sServer;
if (m_Server == NULL)
{
m_Server = new CServer;
}
return m_Server;
}

and i wrote a client that too in MFC which just creates the object every time i click start button
(here always it returns same object's IDispatch pointer)


void CComClientDlg::OnBnClickedStart()
{
// TODO: Add your control notification handler code here

CLSID id = { 0xe856e42c, 0xe479, 0x4008, {0xb2, 0xf8, 0x1, 0xec, 0x9e, 0x5a, 0x84, 0x63} };
COSERVERINFO si;
si.pwszName = OLESTR("127.0.0.1");
si.pAuthInfo = NULL;
si.dwReserved1 = 0;
si.dwReserved2 = 0;
MULTI_QI rgmqi;
rgmqi.pIID = &IID;_IDispatch;
rgmqi.pItf=NULL;
rgmqi.hr=S_OK;
HRESULT hresult = ::CoCreateInstanceEx(
id,
NULL,
CLSCTX_LOCAL_SERVER,
&si, 1, &rgmqi);
if (hresult == S_OK)
{
//hmmm success
;
}
}


but wat happens is when i click the start button 6 times my server is getting crashed Frown
running in debugger alone i could able to find the crash(if not in debugger my server is getting shutdown silently and opening again)

In Debugging what i have found is the reference count of my object is steady getting reduced,

when i try to create the object first time(first time when the OnBnClickedStart is called) the ref count is 0 and next time it becomes 4(i dono how) and when i continuously call OnBnClickedStart for six time server crashes)

am i missing some thing here?

As it is a singleton should i give my one addref and release?

help me please


Thanks,
Jey

jey

QuestionTAPI Looking for minimum required code for making outgoing callsmemberRon Segijn1:30 12 Apr '09  
For one of my customers I simply used the TAPIRequestMakeCall method for making an outgoing call.
The problems is that it triggers Windows Dialer which popups 2 windows.
This is very annoying.
So I am looking for another way to make an outgoing call (not using the requestmakecall method) using the TAPI3LIB.

So my question is, what is the minimum required code/steps for making an outgoing call?

The article at http://msdn.microsoft.com/en-us/library/ms733298(VS.85).aspx[^]

Seems to have too much overhead for me.

Can anyone help me out here?
QuestionAtlAxAttachControl - An outgoing call cannot be made since the application is dispatching an input-syncronous call.memberbfoo7514:20 9 Apr '09  
I'm at the end of my rope here... I've been bashing my head on my keyboard for the last week trying to figure out this issue.

I'm trying to display a flash control on a DirectDraw surface and my call to AtlAxAttachControl fails - preventing the flash player from appearing within the control.

Here's a stripped down version of my code:


#pragma once

#include <string>
#include <windows.h>
#include <exdisp.h>
#include <mshtmlc.h>

#include <atlbase.h>
#include <atlcom.h>
#include <atlwin.h>

using std::string;

#import "PROGID:ShockwaveFlash.ShockwaveFlash" no_namespace raw_interfaces_only

typedef HRESULT (WINAPI *LPAtlAxWinInit) ();
typedef HRESULT (WINAPI *LPAtlAxGetControl)(HWND hwnd, IUnknown** unk);

class FlashViewer
{
public:
FlashViewer();
~FlashViewer();

bool Init(int Width, int Height);

void OpenFlash(const char* filename);

void DrawToSurface(LPDIRECTDRAWSURFACE7 lpdds);

private:
int mViewerWidth;
int mViewerHeight;

HWND mViewerWnd;
IShockwaveFlash* mFlashCtrl;
};

FlashViewer::FlashViewer()
{
mViewerWidth = 0;
mViewerHeight = 0;

mViewerWnd = 0;
mFlashCtrl = NULL;
}

FlashViewer::~FlashViewer()
{
DestroyWindow(this->mViewerWnd);
if (this->mFlashCtrl != NULL)
{
this->mFlashCtrl->Release();
this->mFlashCtrl = NULL;
}
}

bool FlashViewer::Init(int width, int height)
{
LPAtlAxWinInit AtlAxWinInit3 = (LPAtlAxWinInit)GetProcAddress(LoadLibrary("atl"), "AtlAxWinInit");
LPAtlAxGetControl AtlAxGetControl3 = (LPAtlAxGetControl)GetProcAddress(LoadLibrary("atl"), "AtlAxGetControl");

MSG msg;
HRESULT hr = AtlAxWinInit3();

HWND hwnd = CreateWindow("AtlAxWin", "", WS_VISIBLE|WS_POPUP, 0, 0, 1024, 768, 0, 0, 0, 0);

IShockwaveFlash* flash = 0;

hr = CoCreateInstance(__uuidof(ShockwaveFlash), 0, CLSCTX_ALL, __uuidof(IShockwaveFlash), (void **)&flash);
hr = flash->put_WMode(L"transparent");
hr = flash->put_Loop(true);

hr = AtlAxAttachControl(flash, hwnd, NULL);
hr = flash->put_Movie(L"c:\\FrontEnd.swf");

long pVal = -1;
flash->get_ReadyState(&pVal);

return true;
}

void FlashViewer::OpenFlash(const char *filename)
{
this->mFlashCtrl->LoadMovie(0, _bstr_t(filename));
}

void FlashViewer::DrawToSurface(LPDIRECTDRAWSURFACE7 lpdds)
{
if (this->mViewerWnd == NULL)
return;
RECT rect = {0, 0, this->mViewerWidth, this->mViewerHeight};
HDC hdcSurface;
HRESULT hr = lpdds->GetDC(&hdcSurface);
if (FAILED(hr))
return;
SetMapMode(hdcSurface, MM_TEXT);
OleDraw(this->mFlashCtrl, DVASPECT_CONTENT, hdcSurface, &rect);
lpdds->ReleaseDC(hdcSurface);
}


When debugging - the console displays two First-chance exceptions as soon as AtlAxAttachControl() is called... Both are 0x8001010D: An outgoing call cannot be made since the application is dispatching an input-syncronous call.

This problem is totally driving me crazy... PLEASE SOMEONE HELP.
QuestionHow to create new object in C# for reading COM port.membergaurav_quexst2:57 9 Apr '09  
How to create new object in C# for reading COM port.

I am having 'Comet.xyz' object. this object comes from COM port.

please tell me how can i convert following code into c#.

/////////code in delphi


Coment := CreateOleObject('Comet.xyz');
Coment.COmPort="COM1";


please convert it into C#
AnswerRe: How to create new object in C# for reading COM port. [modified]memberVozzie27:23 9 Apr '09  
You can make a reference to the object...

If not then you can use "Late Binding",...

Type type = Type.GetTypeFromProgID("WScript.Shell");
Object oShell = Activator.CreateInstance(type);
Object[] oArgs = {"notepad.exe"};
type.InvokeMember("Run", System.Reflection.BindingFlags.InvokeMethod, Type.DefaultBinder, oShell, oArgs);


I'm not home in C#, but in VB.Net with "Option Strict Off" you can also just write

Dim type As Type = Type.GetTypeFromProgID("WScript.Shell")
Dim oShell As Object = Activator.CreateInstance(type)
oShell.Run "notepad.exe"


GTH

It feels good to learn and achieve

modified on Thursday, April 9, 2009 5:58 PM

QuestionAdd-in express..membergothic_coder2:11 9 Apr '09  
Just like add-in express, do we have another development tool??

I need to add 2 buttons in microsoft outlook express...

Can someone redirect me to relevant sites,articles etc..

Thanks.
QuestionIs VariantChangeType() have problem with BSTR to VT_I4 conversion with even numbers and odd numbersmemberShankarcodebase6:48 8 Apr '09  
Hi Guys,

I am trying to round the value of long value. But i have this value in data type Variant.BSTR.

I can convert to this value by changing its data type from BSTR to VT_I4 through VariantChangeType(), in this conversion this value will be get rounded to nearst integer.

Again i should convert this value from VT_I4 to BSTR by VariantChangeType().

This is working fine for ODD numbers but failing for EVEN numbers.

if(FAILED(VariantChangeType(&vtValue,&vtValue,VARIANT_NOVALUEPROP,VT_I4)))
{
ASSERT(false);
}
if(FAILED(VariantChangeType(&vtValue,&vtValue,VARIANT_NOVALUEPROP,VT_BSTR)))
{
ASSERT(false);
}

Ex: if vt.BSTR = "5.5"
after conversion to VT_I4 its value will be 6
But
if vt.BSTR = "6.5" My expected value is 7 here
but after conversion to VT_I4 its value will be 6 only.....any idea please...need to set anything while using this api...
QuestionDLL missing?membertom5720073:49 8 Apr '09  
Hi,

I need to use the System.Printing.Activation dll bu I'm unabled to find it in the .NET Framework 3.5

I was searching on the net but I can't find it and I saw no other case like mine. Did somebody have tehe same problem I have.

Please help me.

Regards.
AnswerRe: DLL missing?membertom5720073:57 8 Apr '09  
I Just found an answer to my question. The reference i was searching is include into the ReachFramework.dll

apologies
QuestionVB ActiveX in C#membertvks3:13 8 Apr '09  
Hi,

I have a VB code (ActiveX ExE) which has a VB form called DocX.

This form has a GET property (name it retProp) which returns an object.

I have compiled the ActiveX EXE and later used tlbimp from dotnet to generate an Interop.MyProject.dll

Later I have included this dll as a reference in my C# project.

Now I am getting the namespace MyProject.MyInterface.

When I use the following code it says "true"

if (MyInterface.Windows.Exist(ref data) == true)


--> MyInterface.Windows.Exist(ref data) returns the MyInterface.Windows.Window as object

Because MyInterface.Windows.getItem(ref data).Form is returned as an object to me I am not able to Unbox it. I get an error :

System.InvalidCastException: Unable to cast COM object of type 'System.__ComObject' to class type 'VB.Form'. COM components that enter the CLR and do not support IProvideClassInfo or that do not have any interop assembly registered will be wrapped in the __ComObject type. Instances of this type cannot be cast to any other class; however they can be cast to interfaces as long as the underlying COM component supports QueryInterface calls for the IID of the interface.

Pls help.

Regards,

tvks
Questionhow to fix the IWebBrowser2 refresh problemmemberbenpeng23:56 2 Apr '09  
I want display a black background page in a IWebBrowser2. But it always flicker when it is refresh.

So I write following code to fix it.

::SetWindowLong(m_hBrowWnd, GWL_WNDPROC, (LONG)MyBrowWndProc);
m_pBrowWndProc=(WNDPROC)::SetWindowLong(m_hBrowWnd, GWL_WNDPROC, (LONG)MyBrowWndProc);

LRESULT CALLBACK CDlgTest::MyBrowWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
     CDlgTest* pThis=(CDlgTest*)g_pIeTestDialog;
      if(!pThis)
            return FALSE;
     if(message == WM_ERASEBKGND)
     {
          return NULL;
     }
      return CallWindowProc(pThis->m_pBrowWndProc, hWnd, message, wParam, lParam);    
}

It work well at IE 8, but crash at once at IE 6.
Who can help me?
QuestionFree threaded modelmember_808622:25 2 Apr '09  
Will I be able to address all the requirements with a free threaded model? Assuming I have an efficient synchronization mechanism in place. Single,Multi apartments can ever be avoided?

----------------------------
286? WOWW!Red faced

AnswerRe: Free threaded modelmemberRoger Stoltz22:50 2 Apr '09  
_8086 wrote:
Will I be able to address all the requirements with a free threaded model?


Ummm, what requirements? Confused


_8086 wrote:
Single,Multi apartments can ever be avoided?


A COM server resides in either a Single Threaded Apartment or a MultiThreaded Apartment. To avoid the use of them you should not use COM at all....

I guess you have to clarify your question (a lot, probably).


"It's supposed to be hard, otherwise anybody could do it!" - selfquote
"High speed never compensates for wrong direction!" - unknown


GeneralRe: Free threaded modelmember_808623:43 2 Apr '09  
What about Free-Threaded model? Which is analogous to a background thread? Free-Threaded model is Multi-threaded model?

----------------------------
286? WOWW!Red faced

GeneralRe: Free threaded modelmember_808623:53 2 Apr '09  
Ok let me try to explain better.

I write a COM component that runs multiple threads inside. A simple CreateThread used.
I use critical sections to protect objects inside the thread function. What is this model called? I think this is free threaded model.

Also, when I read about STAs they say it deals with UI messages. It makes me tried. After all these brain squeezing efforts to understand COM, when I felt I'm okay with the concepts, a thunder on the head again. What the frack UI messages have got to do with a COM component. I know the dumbness is on my side, but I really don't understand. May be they are talking about Active-x? Understanding this threading models looks like nightmare. If you can help me with a casual explanation. I'd be grateful.

----------------------------
286? WOWW!Red faced

AnswerRe: Free threaded modelmemberRoger Stoltz0:04 3 Apr '09  
Okay.
So how about starting with the articles here at CP?
Lim Bio Liong has written a nice article series that can be found here[^].

There's a lot to be learned about COM and especially the understanding of the concept of apartments.
In short it boils down to that a thread that creates a COM server must always pump messages; it has to do with marshalling and RPC (deep technical stuff).
Free-threading looks a little bit different depending on whether the server is an in-process or an out-of-process server. But in both cases it means that the server will be called in different thread contexts and thus thread synchronization is essential inside the server. To use free-threading you have to create the server inside an MTA. Creating the server inside an STA guarantees that the server will nly be called from the same thread context as long as you obey the COM rules and marshal interfaces properly across apartment boundaries.


"It's supposed to be hard, otherwise anybody could do it!" - selfquote
"High speed never compensates for wrong direction!" - unknown


GeneralRe: Free threaded modelmember_80860:16 3 Apr '09  
Understanding threads inside COM looks like a litmus test for my IQ. Anyway lemme give a try Smile. I will go through those articles your pointed out. Also thanks for the explanations.

----------------------------
286? WOWW!Red faced

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   


Last Updated 9 Aug 2007
Web12 | 2.2.1067 | Advertise | Privacy
Copyright © CodeProject, 1999-2009
All Rights Reserved. Terms of Use