nativeMethod error

  • Thread starter Thread starter GS
  • Start date Start date
G

GS

I was attempting to use the
Guid("B722BCCB-4E68-101B-A2BC-00AA00404770")
for IOleCommandTarget
and Guid("D30C1661-CDAF-11d0-8A3E-00C04FC9E26E") for interface IwebBrowser2

However I got errro
Error 1 'System.Drawing.NativeMethods' is inaccessible due to its protection
level c:\webCtlExtended\WebCtlExtended.cs 182 50 webCtlExtended
and
Error 2 The type name 'OLECMDID' does not exist in the type
'System.Drawing.NativeMethods'
C:\webCtlExtended\webCtlExtended\WebCtlExtended.cs 182 64 webCtlExtended


for

[DispId(0x1f5)]
NativeMethods.OLECMDF QueryStatusWB([In] NativeMethods.OLECMDID
cmdID);
[DispId(0x1f6)]
void ExecWB([In] NativeMethods.OLECMDID cmdID, [In]
NativeMethods.OLECMDEXECOPT cmdexecopt, ref object pvaIn, IntPtr pvaOut);


it appears that the the guid ofr IWebBrowser is wrong
I am using C3 2008 express with target being .net 3.5
 
GS,

Without seeing the relevant code (a short, complete example would be
better), it's difficult to say.

However, the errors indicate that something else is going on. First, it
seems you are trying to access something that is not visible to your code.
The NativeMethods type in the System.Drawing namespace is more than likely
internal to System.Drawing.dll, so I'm not surprized about this.

What exactly are you trying to do? Are you trying to use the OLECMDID
type in a definition of the IOleCommandTarget and IWebBrowser2 interfaces
that you are declaring yourself? If so, you will have to declare this type
yourself, which isn't too hard given the header file (docobj.h).
 
thank you. nice to hear form you again with advice.


I failed to find docobj.h in my system and apparently it comes with inet sdk
which I did not download. I will try look for more detail on the .h file
however I am not all familar with C++ to C# ; may be able do some struct
conversion and simple type though.


I was copying some code from kb to enhance the built-in webbrowser control
by exposing IWebBrowser2

----------------------here is the code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Windows;
using System.Windows.Forms;
using SHDocVw;


// does not work with comimport on IWebBrowser2
public class WebCtlExtended : System.Windows.Forms.WebBrowser
{



public WebCtlExtended()
{
InitializeComponent();

// ------------------------------------------

IWebBrowser2.Visible = VARIANT_TRUE;
if (SUCCEEDED(OleInitialize(null)))
{
IWebBrowser2 pBrowser2;
Object p = null;

//CoCreateInstance(CLSID_InternetExplorer, NULL,
CLSCTX_LOCAL_SERVER,
// IID_IWebBrowser2, (void**)&pBrowser2);
pBrowser2 = new ApplicationId(CLSID_InternetExplorer, p,
CLSCTX_LOCAL_SERVER, IID_IWebBrowser2, pBrowser2);
if (pBrowser2)
{
Object vEmpty = null; //VARIANT vEmpty;
VariantInit(&vEmpty);

BSTR bstrURL = SysAllocString("http://microsoft.com");

HRESULT hr = pBrowser2->Navigate(bstrURL, &vEmpty,
&vEmpty, &vEmpty, &vEmpty);
if (SUCCEEDED(hr))
{
pBrowser2.put_Visible(VARIANT_TRUE);
}
else
{
pBrowser2.Quit(); //pBrowser2->Quit();
}

SysFreeString(bstrURL);
pBrowser2.Release(); //pBrowser2->Release();
}

OleUninitialize();
}
}

private void InitializeComponent()
{
this.SuspendLayout();
this.ResumeLayout(false);

}

private Guid cmdGuid = new
Guid("ED016940-BD5B-11CF-BA4E-00C04FD70816"); //GUID for CGI_IWebBrowser to
inform MSHTML how to process your command IDs. Use the Microsoft .NET
Framework class GUID to do this:
private enum MiscCommandTarget
{
Find = 1,
ViewSource,
Options
}

// ----------------------




}

#region "OLECMD"


public enum OLECMDID
{
// Fields
OLECMDID_PAGESETUP = 8,
OLECMDID_PRINT = 6,
OLECMDID_PRINTPREVIEW = 7,
OLECMDID_PROPERTIES = 10,
OLECMDID_SAVEAS = 4,
OLECMDID_SHOWSCRIPTERROR = 40
}
public enum OLECMDEXECOPT
{
// Fields
OLECMDEXECOPT_DODEFAULT = 0,
OLECMDEXECOPT_DONTPROMPTUSER = 2,
OLECMDEXECOPT_PROMPTUSER = 1,
OLECMDEXECOPT_SHOWHELP = 3
}

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct OLECMDTEXT
{
public uint cmdtextf;
public uint cwActual;
public uint cwBuf;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 100)]
public char rgwz;
}


[StructLayout(LayoutKind.Sequential)]
public class OLECMD
{
[MarshalAs(UnmanagedType.U4)]
public int cmdID;
[MarshalAs(UnmanagedType.U4)]
public int cmdf;
public OLECMD()
{
}
}


[ComImport,
Guid("b722bccb-4e68-101b-a2bc-00aa00404770"),
InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IOleCommandTarget
{
//IMPORTANT: The order of the methods is critical here. You
//perform early binding in most cases, so the order of the methods
//here MUST match the order of their vtable layout (which is
determined by their layout in IDL). The interop calls key off the vtable
ordering,
//not the symbolic names. Therefore, if you switched these method
declarations
//and tried to call the Exec method on an IOleCommandTarget
interface from your
//application, it would translate into a call to the QueryStatus
method instead.
void QueryStatus(ref Guid pguidCmdGroup, UInt32 cCmds,
[MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] OLECMD[]
prgCmds, ref OLECMDTEXT CmdText);
void Exec(ref Guid pguidCmdGroup, uint nCmdId, uint nCmdExecOpt, ref
object pvaIn, ref object pvaOut);
}


#endregion '"OLECMD"


[ComImport,
InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIDispatch),
Guid("D30C1661-CDAF-11d0-8A3E-00C04FC9E26E"),
TypeLibType(TypeLibTypeFlags.FOleAutomation |
(TypeLibTypeFlags.FDual | TypeLibTypeFlags.FHidden))]
public interface IWebBrowser2
{
[DispId(100)]
void GoBack();
[DispId(0x65)]
void GoForward();
[DispId(0x66)]
void GoHome();
[DispId(0x67)]
void GoSearch();
[DispId(0x68)]
void Navigate([In] string Url, [In] ref object flags, [In] ref
object targetFrameName, [In] ref object postData, [In] ref object headers);
[DispId(-550)]
void Refresh();
[DispId(0x69)]
void Refresh2([In] ref object level);
[DispId(0x6a)]
void Stop();
[DispId(200)]
object Application { [return: MarshalAs(UnmanagedType.IDispatch)]
get; }
[DispId(0xc9)]
object Parent { [return: MarshalAs(UnmanagedType.IDispatch)] get; }
[DispId(0xca)]
object Container { [return: MarshalAs(UnmanagedType.IDispatch)]
get; }
[DispId(0xcb)]
object Document { [return: MarshalAs(UnmanagedType.IDispatch)]
get; }
[DispId(0xcc)]
bool TopLevelContainer { get; }
[DispId(0xcd)]
string Type { get; }
[DispId(0xce)]
int Left { get; set; }
[DispId(0xcf)]
int Top { get; set; }
[DispId(0xd0)]
int Width { get; set; }
[DispId(0xd1)]
int Height { get; set; }
[DispId(210)]
string LocationName { get; }
[DispId(0xd3)]
string LocationURL { get; }
[DispId(0xd4)]
bool Busy { get; }
[DispId(300)]
void Quit();
[DispId(0x12d)]
void ClientToWindow(out int pcx, out int pcy);
[DispId(0x12e)]
void PutProperty([In] string property, [In] object vtValue);
[DispId(0x12f)]
object GetProperty([In] string property);
[DispId(0)]
string Name { get; }
[DispId(-515)]
int HWND { get; }
[DispId(400)]
string FullName { get; }
[DispId(0x191)]
string Path { get; }
[DispId(0x192)]
bool Visible { get; set; }
[DispId(0x193)]
bool StatusBar { get; set; }
[DispId(0x194)]
string StatusText { get; set; }
[DispId(0x195)]
int ToolBar { get; set; }
[DispId(0x196)]
bool MenuBar { get; set; }
[DispId(0x197)]
bool FullScreen { get; set; }
[DispId(500)]
void Navigate2([In] ref object URL, [In] ref object flags, [In] ref
object targetFrameName, [In] ref object postData, [In] ref object headers);
[DispId(0x1f5)]
NativeMethods.OLECMDF QueryStatusWB([In] NativeMethods.OLECMDID
cmdID);
// -<<<<<<<<<<<<<< I got error on preceding and next line I suscpect I
got the
// wrong GUID for interface IWebBrowser2 but searching the registry
// HKEY_CLASSES_ROOT\Interface\{D30C1661-CDAF-11D0-8A3E-00C04FC9E26E}
confirms the value
// however there is also
HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Interface\{D30C1661-CDAF-11D0-8A3E-00C04
FC9E26E}, same guid but different key
[DispId(0x1f6)]
void ExecWB([In] NativeMethods.OLECMDID cmdID, [In] OLECMDEXECOPT
cmdexecopt, ref object pvaIn, IntPtr pvaOut);
[DispId(0x1f7)]
void ShowBrowserBar([In] ref object pvaClsid, [In] ref object
pvarShow, [In] ref object pvarSize);
[DispId(-525)]
WebBrowserReadyState ReadyState { get; }
[DispId(550)]
bool Offline { get; set; }
[DispId(0x227)]
bool Silent { get; set; }
[DispId(0x228)]
bool RegisterAsBrowser { get; set; }
[DispId(0x229)]
bool RegisterAsDropTarget { get; set; }
[DispId(0x22a)]
bool TheaterMode { get; set; }
[DispId(0x22b)]
bool AddressBar { get; set; }
[DispId(0x22c)]
bool Resizable { get; set; }
}


Nicholas Paldino said:
GS,

Without seeing the relevant code (a short, complete example would be
better), it's difficult to say.

However, the errors indicate that something else is going on. First, it
seems you are trying to access something that is not visible to your code.
The NativeMethods type in the System.Drawing namespace is more than likely
internal to System.Drawing.dll, so I'm not surprized about this.

What exactly are you trying to do? Are you trying to use the OLECMDID
type in a definition of the IOleCommandTarget and IWebBrowser2 interfaces
that you are declaring yourself? If so, you will have to declare this type
yourself, which isn't too hard given the header file (docobj.h).
<Snipped>
 
GS,

The documentation for OLECMDID has a declaration for the enumeration in
C++. Also, the file might be available in an SDK that is freely available
(you will have to check).

What are you trying to do here? You are extending a WebBrowser control,
and then creating an instance of Internet Explorer to get an implementation
of the IWebBrowser2 interface?

You should be able to directly cast the results of the ActiveXInstance
property on the webbrowser to an IWebBrowser2 reference. There is no need
to try and create a new instance.

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

GS said:
thank you. nice to hear form you again with advice.


I failed to find docobj.h in my system and apparently it comes with inet
sdk
which I did not download. I will try look for more detail on the .h file
however I am not all familar with C++ to C# ; may be able do some struct
conversion and simple type though.


I was copying some code from kb to enhance the built-in webbrowser control
by exposing IWebBrowser2

----------------------here is the code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Windows;
using System.Windows.Forms;
using SHDocVw;


// does not work with comimport on IWebBrowser2
public class WebCtlExtended : System.Windows.Forms.WebBrowser
{



public WebCtlExtended()
{
InitializeComponent();

// ------------------------------------------

IWebBrowser2.Visible = VARIANT_TRUE;
if (SUCCEEDED(OleInitialize(null)))
{
IWebBrowser2 pBrowser2;
Object p = null;

//CoCreateInstance(CLSID_InternetExplorer, NULL,
CLSCTX_LOCAL_SERVER,
// IID_IWebBrowser2, (void**)&pBrowser2);
pBrowser2 = new ApplicationId(CLSID_InternetExplorer, p,
CLSCTX_LOCAL_SERVER, IID_IWebBrowser2, pBrowser2);
if (pBrowser2)
{
Object vEmpty = null; //VARIANT vEmpty;
VariantInit(&vEmpty);

BSTR bstrURL = SysAllocString("http://microsoft.com");

HRESULT hr = pBrowser2->Navigate(bstrURL, &vEmpty,
&vEmpty, &vEmpty, &vEmpty);
if (SUCCEEDED(hr))
{
pBrowser2.put_Visible(VARIANT_TRUE);
}
else
{
pBrowser2.Quit(); //pBrowser2->Quit();
}

SysFreeString(bstrURL);
pBrowser2.Release(); //pBrowser2->Release();
}

OleUninitialize();
}
}

private void InitializeComponent()
{
this.SuspendLayout();
this.ResumeLayout(false);

}

private Guid cmdGuid = new
Guid("ED016940-BD5B-11CF-BA4E-00C04FD70816"); //GUID for CGI_IWebBrowser
to
inform MSHTML how to process your command IDs. Use the Microsoft .NET
Framework class GUID to do this:
private enum MiscCommandTarget
{
Find = 1,
ViewSource,
Options
}

// ----------------------




}

#region "OLECMD"


public enum OLECMDID
{
// Fields
OLECMDID_PAGESETUP = 8,
OLECMDID_PRINT = 6,
OLECMDID_PRINTPREVIEW = 7,
OLECMDID_PROPERTIES = 10,
OLECMDID_SAVEAS = 4,
OLECMDID_SHOWSCRIPTERROR = 40
}
public enum OLECMDEXECOPT
{
// Fields
OLECMDEXECOPT_DODEFAULT = 0,
OLECMDEXECOPT_DONTPROMPTUSER = 2,
OLECMDEXECOPT_PROMPTUSER = 1,
OLECMDEXECOPT_SHOWHELP = 3
}

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct OLECMDTEXT
{
public uint cmdtextf;
public uint cwActual;
public uint cwBuf;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 100)]
public char rgwz;
}


[StructLayout(LayoutKind.Sequential)]
public class OLECMD
{
[MarshalAs(UnmanagedType.U4)]
public int cmdID;
[MarshalAs(UnmanagedType.U4)]
public int cmdf;
public OLECMD()
{
}
}


[ComImport,
Guid("b722bccb-4e68-101b-a2bc-00aa00404770"),
InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IOleCommandTarget
{
//IMPORTANT: The order of the methods is critical here. You
//perform early binding in most cases, so the order of the methods
//here MUST match the order of their vtable layout (which is
determined by their layout in IDL). The interop calls key off the vtable
ordering,
//not the symbolic names. Therefore, if you switched these method
declarations
//and tried to call the Exec method on an IOleCommandTarget
interface from your
//application, it would translate into a call to the QueryStatus
method instead.
void QueryStatus(ref Guid pguidCmdGroup, UInt32 cCmds,
[MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] OLECMD[]
prgCmds, ref OLECMDTEXT CmdText);
void Exec(ref Guid pguidCmdGroup, uint nCmdId, uint nCmdExecOpt,
ref
object pvaIn, ref object pvaOut);
}


#endregion '"OLECMD"


[ComImport,
InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIDispatch),
Guid("D30C1661-CDAF-11d0-8A3E-00C04FC9E26E"),
TypeLibType(TypeLibTypeFlags.FOleAutomation |
(TypeLibTypeFlags.FDual | TypeLibTypeFlags.FHidden))]
public interface IWebBrowser2
{
[DispId(100)]
void GoBack();
[DispId(0x65)]
void GoForward();
[DispId(0x66)]
void GoHome();
[DispId(0x67)]
void GoSearch();
[DispId(0x68)]
void Navigate([In] string Url, [In] ref object flags, [In] ref
object targetFrameName, [In] ref object postData, [In] ref object
headers);
[DispId(-550)]
void Refresh();
[DispId(0x69)]
void Refresh2([In] ref object level);
[DispId(0x6a)]
void Stop();
[DispId(200)]
object Application { [return: MarshalAs(UnmanagedType.IDispatch)]
get; }
[DispId(0xc9)]
object Parent { [return: MarshalAs(UnmanagedType.IDispatch)] get; }
[DispId(0xca)]
object Container { [return: MarshalAs(UnmanagedType.IDispatch)]
get; }
[DispId(0xcb)]
object Document { [return: MarshalAs(UnmanagedType.IDispatch)]
get; }
[DispId(0xcc)]
bool TopLevelContainer { get; }
[DispId(0xcd)]
string Type { get; }
[DispId(0xce)]
int Left { get; set; }
[DispId(0xcf)]
int Top { get; set; }
[DispId(0xd0)]
int Width { get; set; }
[DispId(0xd1)]
int Height { get; set; }
[DispId(210)]
string LocationName { get; }
[DispId(0xd3)]
string LocationURL { get; }
[DispId(0xd4)]
bool Busy { get; }
[DispId(300)]
void Quit();
[DispId(0x12d)]
void ClientToWindow(out int pcx, out int pcy);
[DispId(0x12e)]
void PutProperty([In] string property, [In] object vtValue);
[DispId(0x12f)]
object GetProperty([In] string property);
[DispId(0)]
string Name { get; }
[DispId(-515)]
int HWND { get; }
[DispId(400)]
string FullName { get; }
[DispId(0x191)]
string Path { get; }
[DispId(0x192)]
bool Visible { get; set; }
[DispId(0x193)]
bool StatusBar { get; set; }
[DispId(0x194)]
string StatusText { get; set; }
[DispId(0x195)]
int ToolBar { get; set; }
[DispId(0x196)]
bool MenuBar { get; set; }
[DispId(0x197)]
bool FullScreen { get; set; }
[DispId(500)]
void Navigate2([In] ref object URL, [In] ref object flags, [In] ref
object targetFrameName, [In] ref object postData, [In] ref object
headers);
[DispId(0x1f5)]
NativeMethods.OLECMDF QueryStatusWB([In] NativeMethods.OLECMDID
cmdID);
// -<<<<<<<<<<<<<< I got error on preceding and next line I suscpect I
got the
// wrong GUID for interface IWebBrowser2 but searching the registry
// HKEY_CLASSES_ROOT\Interface\{D30C1661-CDAF-11D0-8A3E-00C04FC9E26E}
confirms the value
// however there is also
HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Interface\{D30C1661-CDAF-11D0-8A3E-00C04
FC9E26E}, same guid but different key
[DispId(0x1f6)]
void ExecWB([In] NativeMethods.OLECMDID cmdID, [In] OLECMDEXECOPT
cmdexecopt, ref object pvaIn, IntPtr pvaOut);
[DispId(0x1f7)]
void ShowBrowserBar([In] ref object pvaClsid, [In] ref object
pvarShow, [In] ref object pvarSize);
[DispId(-525)]
WebBrowserReadyState ReadyState { get; }
[DispId(550)]
bool Offline { get; set; }
[DispId(0x227)]
bool Silent { get; set; }
[DispId(0x228)]
bool RegisterAsBrowser { get; set; }
[DispId(0x229)]
bool RegisterAsDropTarget { get; set; }
[DispId(0x22a)]
bool TheaterMode { get; set; }
[DispId(0x22b)]
bool AddressBar { get; set; }
[DispId(0x22c)]
bool Resizable { get; set; }
}


in
message news:[email protected]...
GS,

Without seeing the relevant code (a short, complete example would be
better), it's difficult to say.

However, the errors indicate that something else is going on. First, it
seems you are trying to access something that is not visible to your
code.
The NativeMethods type in the System.Drawing namespace is more than
likely
internal to System.Drawing.dll, so I'm not surprized about this.

What exactly are you trying to do? Are you trying to use the
OLECMDID
type in a definition of the IOleCommandTarget and IWebBrowser2 interfaces
that you are declaring yourself? If so, you will have to declare this type
yourself, which isn't too hard given the header file (docobj.h).
<Snipped>
 
I am just trying to extend the webbrowser and no new window creation, I want
to capture the event and create anew instance with all the security context
including cookie passed on.


the problem I am dealing with is that the webbrowser is adequate by itself
except when some https webpage link use JavaScript to create some new
windows with script generated url ending up in a new IE instance which by
default does not get the session context of the webbrowser and hence unable
to display the new page.

Please pardon my ignorance in this area. I still have a lot to learn. so
if you don't mind show some actual sample capturing all new window and the
script generated new url so I can pass to another instance of webbrowser or
ie with the session context.


your help is much appreciated ( I have been fighting this for last week,
Google, msdn search and reading without luck. I must critically missed
something

pardon my ignorance,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top