473,545 Members | 1,884 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DLLImports

In a C# program, I find

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

which I converted to

<DllImport("use r32.dll")> _
Public Function ShowWindow(ByVa l 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.H wnd, (int)SW.SHOWNA) ;

was converted to

Dim wasVisible As Boolean = CBool(ShowWindo w(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.Invalid ProgramExceptio n' 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 5728
Define your function ShowWindow as 'Shared' since 'static' from C# converts
to 'Shared' in VB.NET:

<DllImport("use r32.dll")> _
Public Shared Function ShowWindow(ByVa l hwnd As Integer, _
ByVal nCmdShow As Integer) As Integer

End Function

hope that helps..
Imran.

In a C# program, I find

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

<DllImport("use r32.dll")> _
Public Function ShowWindow(ByVa l 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.H wnd, (int)SW.SHOWNA) ;

was converted to

Dim wasVisible As Boolean = CBool(ShowWindo w(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.Invalid ProgramExceptio n' 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****@microso ft.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("use r32.dll")> _
Public Shared Function ShowWindow(ByVa l hwnd As Integer, _
ByVal nCmdShow As Integer) As Integer

End Function

hope that helps..
Imran.

In a C# program, I find

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

<DllImport("use r32.dll")> _
Public Function ShowWindow(ByVa l 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.H wnd, (int)SW.SHOWNA) ;

was converted to

Dim wasVisible As Boolean = CBool(ShowWindo w(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.Invalid ProgramExceptio n' 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
1312
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 directory or a file. But, for some reason, it thinks that every file is a directory! I don't understand the system aspect of the code - I only understand...
2
4535
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 should I use and a sample of source code) in order to get a "byte buf" filled with a packet and using WinPCap lib. Thank you very much,
6
1357
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 true. I do not need to move files etc, simply check if the ftp details that were collected in a web form actually authenticate with the remote ftp...
2
312
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 System.Runtime.InteropServices Public Class Myclass <DllImport("MyDLL")> _ Public Shared Function MyFunction()
2
2375
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 I've created, I was under the impression that .NET automatically called CoInitialise the first time I used a COM object in that thread. Is this the...
0
1132
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 refresher, the reason I want to do this is so I can paste links into a Word document from some Ole object I have lying around. The problem I'm having is...
0
4077
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. Here is the problem. If i select one file and use the standard OPEN context menu, for a .txt file let's say, all is well, but if i select two or more...
0
3247
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 line of code of C++ in my C# code. ------------------------- // If lpVerb really points to a string, ignore this function call and bail out. if...
7
3243
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 System.Collections.Generic namespace. Literature I have read on this ties generics in with collections, hence articulate their examples as such. That's fine,...
0
7486
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7416
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7676
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7776
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6001
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5347
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4965
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3473
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3456
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.