Q: SetWindowLong/GetWindowLong calls for ActiveX IE control 
Author Message
 Q: SetWindowLong/GetWindowLong calls for ActiveX IE control

I host IE ActiveX control and it has its own sunken border I couldn't remove
using GetWindowLong SetWindowLong Win32 API imported functions called with
HWND equal to objWebBrowser.Handle:

int a = GetWindowLong(objWebBrowser.Handle.ToInt32(), -20);
uint d = GetLastError();
SetWindowLong(objWebBrowser.Handle.ToInt32(), -20,  a & ~0x00000200);

GetLastError returns strange code 127 "The specified procedure could not be
found." I think the reason of it in bad import I've done.

I imported functions as follows:

[DllImport("user32.dll", CharSet=CharSet.Auto)]
private static extern int SetWindowLong(
 [MarshalAs(UnmanagedType.U4)] int hWnd,
 [MarshalAs(UnmanagedType.U4)] int nIndex,
 [MarshalAs(UnmanagedType.U4)] int dwNewLong);

[DllImport("user32.dll", CharSet=CharSet.Auto)]
private static extern int GetWindowLong(
 [MarshalAs(UnmanagedType.U4)] int hWnd,
 [MarshalAs(UnmanagedType.U4)] int nIndex);

How to do correctly import?



Wed, 24 Nov 2004 15:49:49 GMT  
 Q: SetWindowLong/GetWindowLong calls for ActiveX IE control


Wed, 18 Jun 1902 08:00:00 GMT  
 Q: SetWindowLong/GetWindowLong calls for ActiveX IE control
Ivan,

1. Never call GetLAstError using PInvoke, instead call Marshal.GetLastWin32Error()and set the DLLImport attribute SetLastError=true
2. Don't call GetLastWin32Error unless the return of the API call is zero, indicating an error.
3. Use Intptr for HANDLES
4. If you want you want your code to be 64 bit compatible use SetWindowLongPtr/GetWindowLongPtr  i.s.o  SetWindowLong/GetWindowLong

 [DllImport("user32.dll", CharSet=CharSet.Auto, SetLastError=true)]
private static extern int SetWindowLong(
    IntPtr hWnd,
    int nIndex,
    int dwNewLong);

 [DllImport("user32.dll", CharSet=CharSet.Auto, SetLastError=true)]
    private static extern int GetWindowLong(
        IntPtr hWnd,
        int nIndex);

int a = GetWindowLong(objWebBrowser.Handle, -20);
if(a == 0)    // Error
    Marshal.GetLastWin32Error();

Willy.

PS. Interop related questions are better answered in microsoft.public.dotnet.framework.interop

Quote:

> I host IE ActiveX control and it has its own sunken border I couldn't remove
> using GetWindowLong SetWindowLong Win32 API imported functions called with
> HWND equal to objWebBrowser.Handle:

> int a = GetWindowLong(objWebBrowser.Handle.ToInt32(), -20);
> uint d = GetLastError();
> SetWindowLong(objWebBrowser.Handle.ToInt32(), -20,  a & ~0x00000200);

> GetLastError returns strange code 127 "The specified procedure could not be
> found." I think the reason of it in bad import I've done.

> I imported functions as follows:

> [DllImport("user32.dll", CharSet=CharSet.Auto)]
> private static extern int SetWindowLong(
>  [MarshalAs(UnmanagedType.U4)] int hWnd,
>  [MarshalAs(UnmanagedType.U4)] int nIndex,
>  [MarshalAs(UnmanagedType.U4)] int dwNewLong);

> [DllImport("user32.dll", CharSet=CharSet.Auto)]
> private static extern int GetWindowLong(
>  [MarshalAs(UnmanagedType.U4)] int hWnd,
>  [MarshalAs(UnmanagedType.U4)] int nIndex);

> How to do correctly import?



Wed, 24 Nov 2004 17:08:36 GMT  
 Q: SetWindowLong/GetWindowLong calls for ActiveX IE control
Marshal.GetLastWin32Error() returns 127 even if GetWindowLong succeeded...



Quote:
> Ivan,

> 1. Never call GetLAstError using PInvoke, instead call

Marshal.GetLastWin32Error()and set the DLLImport attribute SetLastError=true
Quote:
> 2. Don't call GetLastWin32Error unless the return of the API call is zero,

indicating an error.
Quote:
> 3. Use Intptr for HANDLES
> 4. If you want you want your code to be 64 bit compatible use

SetWindowLongPtr/GetWindowLongPtr  i.s.o  SetWindowLong/GetWindowLong
Quote:

>  [DllImport("user32.dll", CharSet=CharSet.Auto, SetLastError=true)]
> private static extern int SetWindowLong(
>     IntPtr hWnd,
>     int nIndex,
>     int dwNewLong);

>  [DllImport("user32.dll", CharSet=CharSet.Auto, SetLastError=true)]
>     private static extern int GetWindowLong(
>         IntPtr hWnd,
>         int nIndex);

> int a = GetWindowLong(objWebBrowser.Handle, -20);
> if(a == 0)    // Error
>     Marshal.GetLastWin32Error();

> Willy.

> PS. Interop related questions are better answered in

microsoft.public.dotnet.framework.interop
Quote:




- Show quoted text -

Quote:
> > I host IE ActiveX control and it has its own sunken border I couldn't
remove
> > using GetWindowLong SetWindowLong Win32 API imported functions called
with
> > HWND equal to objWebBrowser.Handle:

> > int a = GetWindowLong(objWebBrowser.Handle.ToInt32(), -20);
> > uint d = GetLastError();
> > SetWindowLong(objWebBrowser.Handle.ToInt32(), -20,  a & ~0x00000200);

> > GetLastError returns strange code 127 "The specified procedure could not
be
> > found." I think the reason of it in bad import I've done.

> > I imported functions as follows:

> > [DllImport("user32.dll", CharSet=CharSet.Auto)]
> > private static extern int SetWindowLong(
> >  [MarshalAs(UnmanagedType.U4)] int hWnd,
> >  [MarshalAs(UnmanagedType.U4)] int nIndex,
> >  [MarshalAs(UnmanagedType.U4)] int dwNewLong);

> > [DllImport("user32.dll", CharSet=CharSet.Auto)]
> > private static extern int GetWindowLong(
> >  [MarshalAs(UnmanagedType.U4)] int hWnd,
> >  [MarshalAs(UnmanagedType.U4)] int nIndex);

> > How to do correctly import?



Wed, 24 Nov 2004 19:07:26 GMT  
 Q: SetWindowLong/GetWindowLong calls for ActiveX IE control
I assume you are talking about SetWindowsLong returning 0.

You should call SetLastError(0) before calling SetWindowLong.

[DllImport("kernel32.dll)]
     private static extern void SetLastError(int  errorCode)

Willy.

Quote:

> Marshal.GetLastWin32Error() returns 127 even if GetWindowLong succeeded...



> > Ivan,

> > 1. Never call GetLAstError using PInvoke, instead call
> Marshal.GetLastWin32Error()and set the DLLImport attribute SetLastError=true
> > 2. Don't call GetLastWin32Error unless the return of the API call is zero,
> indicating an error.
> > 3. Use Intptr for HANDLES
> > 4. If you want you want your code to be 64 bit compatible use
> SetWindowLongPtr/GetWindowLongPtr  i.s.o  SetWindowLong/GetWindowLong

> >  [DllImport("user32.dll", CharSet=CharSet.Auto, SetLastError=true)]
> > private static extern int SetWindowLong(
> >     IntPtr hWnd,
> >     int nIndex,
> >     int dwNewLong);

> >  [DllImport("user32.dll", CharSet=CharSet.Auto, SetLastError=true)]
> >     private static extern int GetWindowLong(
> >         IntPtr hWnd,
> >         int nIndex);

> > int a = GetWindowLong(objWebBrowser.Handle, -20);
> > if(a == 0)    // Error
> >     Marshal.GetLastWin32Error();

> > Willy.

> > PS. Interop related questions are better answered in
> microsoft.public.dotnet.framework.interop



> > > I host IE ActiveX control and it has its own sunken border I couldn't
> remove
> > > using GetWindowLong SetWindowLong Win32 API imported functions called
> with
> > > HWND equal to objWebBrowser.Handle:

> > > int a = GetWindowLong(objWebBrowser.Handle.ToInt32(), -20);
> > > uint d = GetLastError();
> > > SetWindowLong(objWebBrowser.Handle.ToInt32(), -20,  a & ~0x00000200);

> > > GetLastError returns strange code 127 "The specified procedure could not
> be
> > > found." I think the reason of it in bad import I've done.

> > > I imported functions as follows:

> > > [DllImport("user32.dll", CharSet=CharSet.Auto)]
> > > private static extern int SetWindowLong(
> > >  [MarshalAs(UnmanagedType.U4)] int hWnd,
> > >  [MarshalAs(UnmanagedType.U4)] int nIndex,
> > >  [MarshalAs(UnmanagedType.U4)] int dwNewLong);

> > > [DllImport("user32.dll", CharSet=CharSet.Auto)]
> > > private static extern int GetWindowLong(
> > >  [MarshalAs(UnmanagedType.U4)] int hWnd,
> > >  [MarshalAs(UnmanagedType.U4)] int nIndex);

> > > How to do correctly import?



Wed, 24 Nov 2004 22:28:21 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. IE calling out-of-process ActiveX

2. Qs on Function Call on Array

3. ActiveX control memory management when used in IE

4. ATL ActiveX Control Event not firing in IE?

5. IE 5.x printing and ActiveX controls

6. Unload ActiveX Control from IE?

7. IE ActiveX control and Netscape plug-in

8. Threads, ActiveX Control and IE

9. ActiveX Control's SetTimer Fails with IE Refresh

10. Can IE get events from a ActiveX Control?

11. ActiveX Control's SetTimer Fails with IE Refresh

12. Upload file using IE ActiveX Control

 

 
Powered by phpBB® Forum Software