473,320 Members | 2,004 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

DLLImports

In a C# program, I find

[DllImport("user32")]
public static extern bool ShowWindow(int hwnd, int nCmdShow);

which I converted to

<DllImport("user32.dll")> _
Public Function ShowWindow(ByVal hwnd As Integer, ByVal nCmdShow As Integer)
As Integer
End Function

and, the C#

private enum SW
{
HIDE = 0,
SHOWNORMAL = 1,
NORMAL = 1,
SHOWMINIMIZED = 2,
SHOWMAXIMIZED = 3,
MAXIMIZE = 3,
SHOWNOACTIVATE = 4,
SHOW = 5,
MINIMIZE = 6,
SHOWMINNOACTIVE = 7,
SHOWNA = 8,
RESTORE = 9,
SHOWDEFAULT = 10,
FORCEMINIMIZE = 11,
MAX = 11
}

was converted to

Private Enum SW
HIDE = 0
SHOWNORMAL = 1
NORMAL = 1
SHOWMINIMIZED = 2
SHOWMAXIMIZED = 3
MAXIMIZE = 3
SHOWNOACTIVATE = 4
SHOW = 5
MINIMIZE = 6
SHOWMINNOACTIVE = 7
SHOWNA = 8
RESTORE = 9
SHOWDEFAULT = 10
FORCEMINIMIZE = 11
MAX = 11
End Enum
and, the C#

bool wasVisible = ShowWindow(xl.Hwnd, (int)SW.SHOWNA);

was converted to

Dim wasVisible As Boolean = CBool(ShowWindow(xl.Hwnd, CType(SW.SHOWNA,
Integer)))

Why the bool type was used, I know not, as ShowWindow returns an Integer
type

The code runs correctly if, instead of the Dllimports, I use:

Public Declare Function ShowWindow Lib "user32" (ByVal hwnd As Integer,
ByVal nCmdShow As Integer) As Integer

If I use the DLLImports, I get the following error on the use of ShowWindow:

"An unhandled exception type 'System.InvalidProgramException' occurred
my.exe.

Additional Information: Error: PInvoke item(field, method) must be Static."

What do I need to do to get this to work using the DLLImports?

P.S. Both Option Explicit and Option Strict are On.

The original C# code is from pages 69-74 of Andrew Whitechapels's book
Microsoft .NET Development for Microsoft Office. Bye thee waye, the book is
very useful, tho it is painful to convert the C# to VB .NET. I expect to
learn a lot about .C#/VB NET doing the comnersion manually.
--
http://www.standards.com/; See Howard Kaikow's web site.
Nov 21 '05 #1
2 5713
Define your function ShowWindow as 'Shared' since 'static' from C# converts
to 'Shared' in VB.NET:

<DllImport("user32.dll")> _
Public Shared Function ShowWindow(ByVal hwnd As Integer, _
ByVal nCmdShow As Integer) As Integer

End Function

hope that helps..
Imran.

In a C# program, I find

[DllImport("user32")]
public static extern bool ShowWindow(int hwnd, int nCmdShow);
which I converted to

<DllImport("user32.dll")> _
Public Function ShowWindow(ByVal hwnd As Integer, ByVal nCmdShow As
Integer)
As Integer
End Function
and, the C#

private enum SW
{
HIDE = 0,
SHOWNORMAL = 1,
NORMAL = 1,
SHOWMINIMIZED = 2,
SHOWMAXIMIZED = 3,
MAXIMIZE = 3,
SHOWNOACTIVATE = 4,
SHOW = 5,
MINIMIZE = 6,
SHOWMINNOACTIVE = 7,
SHOWNA = 8,
RESTORE = 9,
SHOWDEFAULT = 10,
FORCEMINIMIZE = 11,
MAX = 11
}
was converted to

Private Enum SW
HIDE = 0
SHOWNORMAL = 1
NORMAL = 1
SHOWMINIMIZED = 2
SHOWMAXIMIZED = 3
MAXIMIZE = 3
SHOWNOACTIVATE = 4
SHOW = 5
MINIMIZE = 6
SHOWMINNOACTIVE = 7
SHOWNA = 8
RESTORE = 9
SHOWDEFAULT = 10
FORCEMINIMIZE = 11
MAX = 11
End Enum
and, the C#

bool wasVisible = ShowWindow(xl.Hwnd, (int)SW.SHOWNA);

was converted to

Dim wasVisible As Boolean = CBool(ShowWindow(xl.Hwnd, CType(SW.SHOWNA,
Integer)))

Why the bool type was used, I know not, as ShowWindow returns an
Integer type

The code runs correctly if, instead of the Dllimports, I use:

Public Declare Function ShowWindow Lib "user32" (ByVal hwnd As
Integer, ByVal nCmdShow As Integer) As Integer

If I use the DLLImports, I get the following error on the use of
ShowWindow:

"An unhandled exception type 'System.InvalidProgramException' occurred
my.exe.

Additional Information: Error: PInvoke item(field, method) must be
Static."

What do I need to do to get this to work using the DLLImports?

P.S. Both Option Explicit and Option Strict are On.

The original C# code is from pages 69-74 of Andrew Whitechapels's book
Microsoft .NET Development for Microsoft Office. Bye thee waye, the
book is very useful, tho it is painful to convert the C# to VB .NET. I
expect to learn a lot about .C#/VB NET doing the comnersion manually.


Nov 21 '05 #2
Thanx.

That fixed it.

But, I SWEAR that I had done that before.
That's what I get for swearing.
My fat fingers must have done something else wrong.

--
http://www.standards.com/; See Howard Kaikow's web site.
"Imran Koradia" <no****@microsoft.com> wrote in message
news:13**********************@news.microsoft.com.. .
Define your function ShowWindow as 'Shared' since 'static' from C# converts to 'Shared' in VB.NET:

<DllImport("user32.dll")> _
Public Shared Function ShowWindow(ByVal hwnd As Integer, _
ByVal nCmdShow As Integer) As Integer

End Function

hope that helps..
Imran.

In a C# program, I find

[DllImport("user32")]
public static extern bool ShowWindow(int hwnd, int nCmdShow);
which I converted to

<DllImport("user32.dll")> _
Public Function ShowWindow(ByVal hwnd As Integer, ByVal nCmdShow As
Integer)
As Integer
End Function
and, the C#

private enum SW
{
HIDE = 0,
SHOWNORMAL = 1,
NORMAL = 1,
SHOWMINIMIZED = 2,
SHOWMAXIMIZED = 3,
MAXIMIZE = 3,
SHOWNOACTIVATE = 4,
SHOW = 5,
MINIMIZE = 6,
SHOWMINNOACTIVE = 7,
SHOWNA = 8,
RESTORE = 9,
SHOWDEFAULT = 10,
FORCEMINIMIZE = 11,
MAX = 11
}
was converted to

Private Enum SW
HIDE = 0
SHOWNORMAL = 1
NORMAL = 1
SHOWMINIMIZED = 2
SHOWMAXIMIZED = 3
MAXIMIZE = 3
SHOWNOACTIVATE = 4
SHOW = 5
MINIMIZE = 6
SHOWMINNOACTIVE = 7
SHOWNA = 8
RESTORE = 9
SHOWDEFAULT = 10
FORCEMINIMIZE = 11
MAX = 11
End Enum
and, the C#

bool wasVisible = ShowWindow(xl.Hwnd, (int)SW.SHOWNA);

was converted to

Dim wasVisible As Boolean = CBool(ShowWindow(xl.Hwnd, CType(SW.SHOWNA,
Integer)))

Why the bool type was used, I know not, as ShowWindow returns an
Integer type

The code runs correctly if, instead of the Dllimports, I use:

Public Declare Function ShowWindow Lib "user32" (ByVal hwnd As
Integer, ByVal nCmdShow As Integer) As Integer

If I use the DLLImports, I get the following error on the use of
ShowWindow:

"An unhandled exception type 'System.InvalidProgramException' occurred
my.exe.

Additional Information: Error: PInvoke item(field, method) must be
Static."

What do I need to do to get this to work using the DLLImports?

P.S. Both Option Explicit and Option Strict are On.

The original C# code is from pages 69-74 of Andrew Whitechapels's book
Microsoft .NET Development for Microsoft Office. Bye thee waye, the
book is very useful, tho it is painful to convert the C# to VB .NET. I
expect to learn a lot about .C#/VB NET doing the comnersion manually.


Nov 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: jennifereden.price | last post by:
Hi, I have the following function in a project that implements a shell extension. This function shows all the files that the users has selected and attempts to determine whether it is a...
2
by: Nuno Magalhaes | last post by:
Hello all, Below I have a function that captures a packet and sends that packet to a Receive function (wether it is sent or received). I'm asking what functions should I use (what imports...
6
by: Daren Hawes | last post by:
Hi, My web host has a low security setting on the shared .net server I use. I cannot use third party dll's or install assemblies in the GAC. All I need to do is verify that a FTP login is...
2
by: John Dann | last post by:
One detail about using DLLImports as part of the PInvoke process that I don't understand: I'm trying to access a function (eg MyFunction) in a 3rd party DLL so I create a class: Imports...
2
by: Robin Tucker | last post by:
I need to use OleSetClipboard in my VB.NET application. Unfortunately, when I do the result returned is -2147221008 (CoInitialise has not been called). As I am using OleSetClipboard from a thread...
0
by: Robin Tucker | last post by:
I'm going to kindof restart this thread, because its going up in the list (on my browser anyway). I'm still not able to call OleSetClipboard from within my thread in my VB application. As a...
0
by: lushdog | last post by:
Hi, i'm writing a shell extension in c# that will add two menu's to the right-click menu of explorer if any file is selected, i.e. it's registered in the * section of Classes in the registry. ...
0
by: lushdog | last post by:
Hi, i'm having a little problem with my context menu handler. Basically if i select multiple files and right-click OPEN or EDIT, it uses my context menu to open it. It is because i am missing this...
7
by: SpotNet | last post by:
Hello NewsGroup, Reading up on Generics in the .NET Framework 2.0 using C# 2005 (SP1), I have a question on the application of Generics. Knowingly, Generic classes are contained in the...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.