|
Let me clarify now.!
Forget about COM.
I have Win32 Type say.. (MyStruct) and it contains some virtual functions. Now this type would contains an extra member(hidden) i.e vpVtable that's pointing to some vtable's base address which this type contains because it has some virtual functions.
Right...?
Now I want to access some how this vtable's base address or some how the rva to this vtable's address. I have read the documentation of DIA SDK. and it gives you every information what pdb file contains. Now I am giving the pdb file of that binary(WIN32 Dll/EXE) which contains a type(i.e struct namely MyStruct) which in turns contains some virtual functions.
So If some how I can point "MyStruct" and can get its contained vtable's base address.
If still any confusion in understanding the context, do let me know then..
|
|
|
|
|
OK, I think I understand your problem. However, I'm afraid I have never looked into PDB file so cannot offer any suggestions on that. You may find this article[^] useful as he goes into the structure of vtables in C and how they match with C++ classes.
Just say 'NO' to evaluated arguments for diadic functions! Ash
|
|
|
|
|
I support an application that is a combination of vb6 and .net components. I am trying to replace a vb6 dll with an equivalent in c# but I've got stuck on how to query the properties of a com object that is passed as Object.
The vb6 form instantiates a .net object through COM and then passes a reference to itself but as an object, not a specific type:
public bool Init(ref ADOConn.STConnector db, object MREForm, string user)
In VB i could query any public variables on the form for example:
dim loc as string = MREForm.Location
If I use reflection, all I get is the properties of the object type, not the underlying COM type. How can I do the same thing in C#?
Thanks for any help on this.
|
|
|
|
|
In C#, you just use a type cast.
IMyInterface myInt = (IMyInterface)MREForm;
|
|
|
|
|
Thanks for the answer, but in order to cast, you need to have a type to cast to. In this case, the variable being passed (as an object), is actually a vb6 form, and to get the type means that I need a reference to the vb6 dll, and the form needs to be an exported type.
If I was using VB.net (and I have tried this), I can just reference properties of the object without casting, or creating a reference, presumably using late binding to query the object at runtime "under the bonnet" - this is all taken care of for the VB developer.
My question is: how can I do the same thing in c#?
To clarify the sample code:
VB6 code:
dim obj as MREPlugin32.MREPlugin<br />
...<br />
set obj = new MREPlugin32.MREPlugin<br />
obj.Init(Me)<br />
VB.net code (this works):
public Sub Init(obj as Object)<br />
dim location as string = obj.Location<br />
End Sub<br />
So how can I do this?
C# Code:
public Void Init(object obj)<br />
{<br />
string location = obj.Location;
}<br />
|
|
|
|
|
Hello cable beach,
1.
>> So how can I do this?
>> C# Code:
>> public Void Init(object obj)
>> {
>> string location = obj.Location; // Somehow, without any external references.
>> }
1.1 Unfortunately, this syntax style (indicating a dynamic call to the Location property of a late-bound object) is not possible in C#.
1.2 To make a late bound call to an imported COM object's method or property, you must use the static Type.InvokeMember() function.
1.3 Here are links to 2 useful short articles explaining this :
Calling a COM Component From C# (Late Binding)
http://www.c-sharpcorner.com/UploadFile/psingh/CallingCOMComponentFromCSharp12022005231615PM/CallingCOMComponentFromCSharp.aspx[^]
Late Binding with Reflection
http://www.c-sharpcorner.com/UploadFile/samhaidar/LateBindingWithReflection09122005053810AM/LateBindingWithReflection.aspx[^]
2.
>> VB.net code (this works):
>> public Sub Init(obj as Object)
>> dim location as string = obj.Location
>> End Sub
2.1 Although I do not know enough about VB.NET, I am not surprised that the above syntactic expression is possible. It is likely designed to be so since this is definitely possible in VB6.0.
2.2 I believe that the restriction in C# is probably due to strict type checking which is enforced in languages like C++.
- Bio.
|
|
|
|
|
Yeah, I tried using reflection, but this still requires you have a reference to the underlying type.
In the end I just switched the project to VB.net, and it works. I still find it surprising that there is something vb.net can do that c# can't.
Anyway, thanks for your input.
|
|
|
|
|
Hi all.
I develop a shell extension. My problem is that after registering it, right click on a file is needed at windows start up to explorer load my shell.
It's type is context menu. Is there any type that not need right clicking on a file?
If you know a solution, please share with me.
Thanks a'lot.
|
|
|
|
|
PROBLEM
1. How do i programmatically scroll an IWebBrowser2 control in all IE versions?
2. Why is it that the code i have runs in IE6 but crashes in IE7?
3. Follow-up to question(2), is there a way to work around the Access Violation in mshtml.dll when calling functions from the IHTMLWindow2, IHTMLElement2, IHTMLDocument2 and IHTMLDocument3? (ex. get_scrollTop, get_scrollHeight, get_ScrollWidth, get_parentWindow)
THANKS!
CODE
BOOL CBrowserControl::Scroll(LONG scrollType)
{
CComPtr<IDispatch> spDoc;
long scrollPos;
m_spWebBrowser->get_Document(&spDoc);
IHTMLDocument2 *pDocument = NULL;
HRESULT hresult = spDoc->QueryInterface( IID_IHTMLDocument2, (void**)&pDocument );
IHTMLElement *pBody = NULL;
hresult = pDocument->get_body( &pBody );
IHTMLElement2 *pElement = NULL;
hresult = pBody->QueryInterface(IID_IHTMLElement2,(void**)&pE lement);
IHTMLWindow2 *pWindow = NULL;
hresult = pDocument->get_parentWindow( &pWindow );
long scrollwidth, scrollheight;
pElement->get_scrollHeight(&scrollheight);
pElement->get_scrollWidth(&scrollwidth);
long page;
m_spWebBrowser->get_Height(&page);
switch(scrollType)
{
case StepDown:
................
}
pWindow->scrollBy( 0, scrollPos );
return true;
}
|
|
|
|
|
DETAILS
Good day..
I know it's quite a long shot, but I have this problem.. And I've ran out of places to ask for help for..
I am supposed to make my webbrowser control scroll depending on what scrollType I pass. Well, everything worked fine... that is, in IE6.
My code crashes in IE7 at get_parentWindow, get_scrollHeight (and perhaps also in scrollBy). They all return access violations.
Trying other solutions on the net didn't help, IE7 still crashes with calling functions (like get_scrollTop and etc)... I already tried scrolling using IHTMLElement2. But no luck... I also tried IHTMLDocument3->get_documentElement and used that for scrolling, still... no sunshine in sight.
Is this an IE thing? or are there settings I failed to look at? Does anyone know by chance a way to work around this? it's really not good to just restrict users from using my scrolling functions if they don't use ie6.
i am kinda desperate now.
will be forever grateful for the help.
|
|
|
|
|
Hello
I have this program which uses a COM DLL.
On one computer all works fine.
On another machine, coinitialize keeps returning 3 and fails.
Anybody seen this return code before?
Thanks
alex
'Architecture is music frozen in space.'
|
|
|
|
|
Are you sure about the returned HRESULT ?
According to the CoInitialize Function (COM)[^], the possible results could be the ones below (see A lot of HRESULT codes...[^] for their numeric values):
E_INVALIDARG = 0x80070057 = -2147024809E_OUTOFMEMORY = 0x8007000E = -2147024882E_UNEXPECTED = 0x8000FFFF = -2147418113S_OK = 0x00000000 = 0S_FALSE = 0x00000001 = 1RPC_E_CHANGED_MODE = 0x80010106 = -2147417850
Then it seems that 3 is not a possible result; not only, I was not able to find a description for it anyway, according to Interpreting HRESULT Values[^], such a value doesn't indicates a failure (because the most significant bit is not set).
In your application are you testing for specific values or are you using the SUCCEEDED() macro? When using COM is preferable to always use that macro to distinguish between success and failure...
modified on Friday, October 15, 2010 5:52 AM
|
|
|
|
|
I know that and I haven't been able to find this code either.
3 is supposed to be a success code (bit 0 == 0), but apparently it is not.
I am using SUCCEEDED, but the program kept failing further down the line, so I ran it thru the debugger and this is the HRESULT CoInitialize() returns.
alex
'Architecture is music frozen in space.'
|
|
|
|
|
Hi,
I would like to know that how to get the list of methods in OCX and how to invoke the particular method with the input parameters?
|
|
|
|
|
An OCX is nothing but a COM component.
To access COM methods in managed code, you must do COM interop.
|
|
|
|
|
Can anybody help me programatically using COM components to get the solution for converting any type of document to PDF format
we already tried through this coding:
public static void ConverWordToPDF(string Filepath, string Targetpath)
{
object Unknown = Type.Missing;
object Source = Filepath;
object Target = Targetpath;
ApplicationClass MSdoc = new ApplicationClass();
try
{
MSdoc.Visible = false;
MSdoc.Documents.Open(ref Source, ref Unknown,
ref Unknown, ref Unknown, ref Unknown,
ref Unknown, ref Unknown, ref Unknown,
ref Unknown, ref Unknown, ref Unknown,
ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown);
MSdoc.Application.Visible = false;
MSdoc.WindowState = Microsoft.Office.Interop.Word.WdWindowState.wdWindowStateMinimize;
object format = Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatPDF;
MSdoc.ActiveDocument.SaveAs(ref Target, ref format,
ref Unknown, ref Unknown, ref Unknown,
ref Unknown, ref Unknown, ref Unknown,
ref Unknown, ref Unknown, ref Unknown,
ref Unknown, ref Unknown, ref Unknown,
ref Unknown, ref Unknown);
}
catch (Exception e)
{
log.Info("Converted Word to PDF", e);
}
finally
{
if (MSdoc != null)
{
MSdoc.Documents.Close(ref Unknown, ref Unknown, ref Unknown);
}
MSdoc.Quit(ref Unknown, ref Unknown, ref Unknown);
}
}
Normally in while runing this application in local its working fine in XP System:
while run through IIS i getting the following error:
System.Runtime.InteropServices.COMException (0x800A11FD):
===================
System.Runtime.InteropServices.COMException (0x800A11FD):
This method or property is not available because a document window is not active.
at Microsoft.Office.Interop.Word.Documents.Close(Object& SaveChanges,
Object& OriginalFormat, Object& RouteDocument)
Can anybody suggest me how to resolve it or any new solution for conversion process
Thanks
Regards
Hemananthan>S
|
|
|
|
|
Hi,
I am also facing the same problem if any body knows solution please let us know.
Thanks,
Venu
|
|
|
|
|
use primopdf software you can easily download from the net
|
|
|
|
|
Hi. I am a physicist. I am trying to work with an imported activex control (ocx file) on Delphi. There are 3 automation interfaces in the library: IGraph, IGraphAxes and IAxis. The structure of the library is such that:
===IGraph’s properties:===
Idispatch* IGraphAxes;
... //other members
===IGraphAxes’ properties:===
Idispatch* XAxis;
Idispatch* YAxis;
Idispatch* ZAxis;
integer Color;
integer Style;
… //other members
===IAxis properties:===
float Min, Max;
Boolean ShowNumbers;
… //other members
From IGraph, I am able to get an access to simple members of IGraphAxes (Color and Style) using GetIDsOfNames() and Invoke() functions. But when I try to get an access to XAxis (or YAxis, Zaxis) it generates an error. First, I use GetIDsOfNames() and it returns the dispid of XAxis without any problem. But when I call Invoke with that dispid there is an error “Access violation at address …”. It seems, the idispatch pointer Xaxis points to nothing. How can I solve this? How to make
Idispatch* Xaxis
and
IAxis interface attached to each other (or how to make idispatch* XAxis point to IAxis)?
Thanks in advance.
|
|
|
|
|
Not sure how exactly to get it done in Delphi, but the normal procedure to get one interface pointer from a method in another is to use QueryInterface with the IID of the new interface.
|
|
|
|
|
Hi. Thanks for your reply. Actually the activex control is a third-party visual component for plotting some 3d graphics. When I import the ocx file into Delphi, it appears on the ActiveX tab of the Component Palette. I just drag it with mouse and put on a form and an object
Graph1: TGraph;
is automatically added to my code. Its properties and events become visible in the Object Inspector window. Now I want to get an access to the control’s axes from my code. As you can see, the property <Idispatch * IGraphAxes> represents coordinate axes. Also I guess that IGraphAxes’ XAxis/YAxis/ZAxis members are idispatch pointers of type IGraphAxis. I wrote the following procedures to access an idispatch interface:
procedure TForm2.GetProperty(dispobj: IDispatch; PropertyName: WideString;
var retvalue: Variant; Sender: TObject);
var hr: HRESULT;
DispId: integer;
value: Variant;
params: TDispParams;
begin
hr:=dispobj.GetIDsOfNames(GUID_NULL,@PropertyName, 1, LOCALE_SYSTEM_DEFAULT, @DispId);
Label1.Caption:=inttostr(DispId);
hr:=dispobj.Invoke(DispId,GUID_NULL,LOCALE_SYSTEM_DEFAULT,DISPATCH_PROPERTYGET,
Params,@Value,nil,nil);
Retvalue:=Value;
Label2.Caption:=inttostr(value);
end;
procedure TForm2.SetProperty(dispobj: IDispatch; PropertyName: WideString; Value: OLEVariant;
Sender: TObject);
var
hr: HRESULT;
DispId: integer;
params: TDispParams;
begin
hr:=dispobj.GetIDsOfNames(GUID_NULL,@PropertyName,1, LOCALE_SYSTEM_DEFAULT, @DispId);
Label1.Caption:=inttostr(DispId);
params.rgvarg:=@Value;
params.rgdispidNamedArgs:=@DispIDArgs;
params.cArgs:=1;
params.cNamedArgs:=1;
hr:=dispobj.Invoke(DispId,GUID_NULL,LOCALE_SYSTEM_DEFAULT,
DISPATCH_PROPERTYPUT,Params,nil,nil,nil);
end;
They work fine with Color and Style properties of IGraphAxes:
GetProperty(Graph1.GraphAxes, 'Color', retvalue, Sender);
Or
SetProperty(Graph1.GraphAxes, 'Color',value,Sender);
But how to get full access to XAxis/YAxis/ZAxis members of IGraphAxes?
|
|
|
|
|
Hello Altankhuu,
>> First, I use GetIDsOfNames() and it returns the dispid of XAxis without any problem. But when I call Invoke with that dispid there is an error “Access violation at address …”.
The sequence should be :
IGraph.GetIDsOfNames() to obtain dispid of IGraphAxes property.
IGraph.Invoke() (with above dispid) to obtain IDispatch* of IGraphAxes.
IGraphAxes.GetIDsOfNames() to get dispid of XAxis.
IGraphAxes.Invoke() (with above dispid) to obtain IDispatch* of XAxis.
You then call GetIDsOfNames() and Invoke() on the returned XAxis IDispatch pointer.
- Bio.
|
|
|
|
|
I'm using BO XI R2.
I want to modify the report.
Following is a code snippet which throws InvalidCastException;
and under that the Message is No Such Interfaces Supported.
Kindly suggest me a solution, if you have been able to crack it.
Also any ideas why such an exception.
using CrystalDecisions.CrystalReports.TemplateEngine;
using CrystalDecisions.ReportAppServer.ClientDoc;
using CrystalDecisions.ReportAppServer.ObjectFactory;
using CrystalDecisions.ReportAppServer.DataDefModel;
using CrystalDecisions.ReportAppServer.Controllers;
using CrystalDecisions.ReportAppServer.CommonObjectModel;
using CrystalDecisions.ReportAppServer.ReportDefModel;
ReportClientDocument reportClientDocument = new ReportClientDocument();
SessionMgr sessionMgr = new SessionMgr();
EnterpriseSession enterpriseSession;
EnterpriseService enterpriseService;
InfoStore infoStore;
InfoObjects infoObjects;
InfoObject infoObject;
ReportAppFactory reportAppFactory;
string sampleReportName;
enterpriseSession = sessionMgr.Logon("administrator","","localhost","secEnterprise");
enterpriseService = enterpriseSession.GetService("InfoStore");
infoStore = new InfoStore(enterpriseService);
sampleReportName = "World Sales Report";
infoObjects = infoStore.Query("Select SI_ID From CI_INFOOBJECTS Where SI_NAME='" + sampleReportName + "' And SI_INSTANCE=0");
infoObject = infoObjects[1];
reportAppFactory = (ReportAppFactory)enterpriseSession.GetService("","RASReportFactory").Interface;
reportClientDocument = reportAppFactory.OpenDocument(infoObject.ID,0);
reportClientDocument = reportAppFactory.OpenDocument(infoObject.ID,0);
code segment throws the Exception
modified on Tuesday, September 7, 2010 2:18 AM
|
|
|
|
|
Please do not post the same question in more than one forum.
It's time for a new signature.
|
|
|
|
|
I'm developing a COM object in a dll. The object takes an IUnknown** parameter.
interface IPasser : IDispatch{
[id(1), helpstring("method Pass")]
HRESULT Pass([in]IUnknown* ptr);};
When using it in-process I can send NULL as parameter, but when I instantiate the com object usign a surrogage usign CLSCTX_LOCAL_SERVER I get an error message 0x800706f4, "A null reference pointer was passed to the stub."
IPasserPtr obj;
IUnknown* ptr;hr = obj.CreateInstance (CLSID_Passer, 0, CLSCTX_LOCAL_SERVER);
hr = obj->raw_Pass (0);
hr = obj->raw_Pass (&ptr);
This is only a problem when I use double indirection, not when I use an ordinary IUnknown*.
Can anyone tell me why this is not allowed and how to change the implementation to be able to send a NULL pointer.
/Per
|
|
|
|
|