I'm trying to "isolate" some unmanaged calls to DLLs in a separate namespace
so I can have all the unmanaged calls to DLL functions in a separate module
and then these can be called from any other module using the "Imports"
statement. But I can't get it to work, at least not in the manner that I'd
prefer.
You can call the functions using the fully-qualified name, e.g.
"MySpecial.Unma nagedCode.MyFun ction". But I want to be able to work in a
similar manner to the the third test below and call the functions without
having to do this, i.e. just call the function MyFunction() directly in my
main code. This approach works fine if you have a proper class, and
Intellisense "sort of" seems to be seeing the namespace and functions names,
but it won't compile. Any suggestions?
Example:-
FIRST TEST - TWO SIMPLE MODULES
-- WORKS OK
Module Module1
Sub Main()
'Do equivalent of MsgBox("Hello World") using Win32 API
MessageBox(vbNu llString, "Hello world", "MessageBox ", 0)
End Sub
End Module
Module Module2
Public Declare Function MessageBox Lib "user32" Alias "MessageBox A"
(ByVal hWnd As Integer, ByVal lpText As String, ByVal lpCaption As String,
ByVal wType As Integer) As Integer
End Module
SECOND TEST - put win32 function in a namespace, call with full dotted name
-- WORKS OK
Module Module1
Sub Main()
MyWin32Namespac e.MessageBox(vb NullString, "Hello world",
"MessageBox ", 0)
End Sub
End Module
Namespace MyWin32Namespac e
Module Module2
Public Declare Function MessageBox Lib "user32" Alias "MessageBox A"
(ByVal hWnd As Integer, ByVal lpText As String, ByVal lpCaption As String,
ByVal wType As Integer) As Integer
End Module
End Namespace
THIRD TEST - try to Import namespace to avoid having to use the
fully-qualified name each time
-- FAILS
Imports MyWin32Namespac e
Module Module1
Sub Main()
MessageBox(vbNu llString, "Hello world", "MessageBox ", 0)
End Sub
End Module
Module1.vb(1): Namespace or type 'MyWin32Namespa ce' for the Imports
'MyWin32Namespa ce' cannot be found.
Module1.vb(5): Name 'MessageBox' is not declared. 4 2520
>Module1.vb(1 ): Namespace or type 'MyWin32Namespa ce' for the Imports 'MyWin32Namesp ace' cannot be found. Module1.vb(5 ): Name 'MessageBox' is not declared.
Check your project properties if you have a root namespace set.
Assuming you have a root namespace of MyProject, you have to change
the imports statement to
Imports MyProject.MyWin 32Namespace
Mattias
--
Mattias Sjögren [C# MVP] mattias @ mvps.org http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
> I'm trying to "isolate" some unmanaged calls to DLLs in a separate namespace so I can have all the unmanaged calls to DLL functions in a separate module and then these can be called from any other module using the "Imports" statement. But I can't get it to work, at least not in the manner that I'd prefer.
What you are trying is ok by me, but FYI Fxcop disapproves. They want you
to put all unmanaged declares in one of the native method classes
(NativeMethods, SafeNativeMetho ds, UnsafeNativeMet hods). They discuss some
rules about these classes. The consequence is that you would always have to
qualify the api call like NativeMethods.B itBlt(...), and that defeats the
purpose of your inquiry in the first place. Just an FYI about an Fxcop style
rule.
"AMercer" <AM*****@discus sions.microsoft .com> schrieb: I'm trying to "isolate" some unmanaged calls to DLLs in a separate namespace so I can have all the unmanaged calls to DLL functions in a separate module and then these can be called from any other module using the "Imports" statement. But I can't get it to work, at least not in the manner that I'd prefer.
What you are trying is ok by me, but FYI Fxcop disapproves. They want you to put all unmanaged declares in one of the native method classes (NativeMethods, SafeNativeMetho ds, UnsafeNativeMet hods). They discuss some rules about these classes.
ACK:
<URL:http://blogs.msdn.com/brada/articles/361363.aspx>
-> "Naming Conventions"
--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
"Mattias Sjögren" <ma************ ********@mvps.o rg> wrote in message
news:eh******** ******@TK2MSFTN GP12.phx.gbl... Module1.vb(1 ): Namespace or type 'MyWin32Namespa ce' for the Imports 'MyWin32Namesp ace' cannot be found. Module1.vb(5 ): Name 'MessageBox' is not declared.
Check your project properties if you have a root namespace set. Assuming you have a root namespace of MyProject, you have to change the imports statement to
Imports MyProject.MyWin 32Namespace
Mattias
-- Mattias Sjögren [C# MVP] mattias @ mvps.org http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com Please reply only to the newsgroup.
Mattias,
Thank you. That works perfectly. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Tim Tyler |
last post by:
PHP puts most of its functions into a big flat global namespace.
That leads to short function names - but creates a namespace
minefield for programmers.
Lots of the functions are legacies from the days before PHP
got object-oriented features.
For instance we currently have:
|
by: Razmig K |
last post by:
Dear mates,
This is a small survey for C++ programmers to speak their mind about
the uses and/or potential advantages and disadvantages resulting from
the use of the aforementioned C++ feature in ralistic code in various
programming domains.
Thank you.
//rk
|
by: John L. Clark |
last post by:
I am curious as to the rationale, and effect, of having default
namespaces not applying (directly) to attributes (see
http://www.w3.org/TR/REC-xml-names/#defaulting). Given an attribute
without a namespace prefix, what is its namespace, if default
namespaces do not apply? Are (either of) prefixed or non-prefixed
attributes correct? For example, are the following equivalent:
<html:br class="foo"...
|
by: Patrick Guio |
last post by:
Dear all,
I have some problem with insertion operator together with namespace.
I have a header file foo.h containing declaration of classes, typedefs and
insertion operators for the typedefs in a named namespace
namespace foo
{
class Foo
|
by: David B. Bitton |
last post by:
I am having a problem deserializing XML when the root node is missing a
namespace declaration. My Type has an XmlTypeAttribute with a namespace
defined. If I attempt to deserialize the XML, I get the dreaded
<elementname xmlns=''> was not expected
exception. If I comment out the XmlTypeAttribute, it works just fine. Just
so you know, when I instantiate an instance of an XmlSerializer, I pass a
default namespace to the ctor. ...
| |
by: Mike Oliszewski |
last post by:
Given the following c# code:
namespace Company2
{
public class SomeFunctions
{
public void FunctionA()
{
// Do Something.
}
|
by: Mike Fiedler |
last post by:
On a client web services request, I have a SoapExtension that is adding
a header to the message in the BeforeSerialize stage.
If the Web Service request is for an operation with
style="document"/use="literal",
everything works fine - the header is added, message is serialized and all
is ok.
If the Web Service request is for an operation with style="rpc"/use="encoded":
|
by: james.cssa |
last post by:
I want to declare namespace prefix in the Envelope element (i.e.
xmlns:xsi and xmlns:xsd) so that the document will be serialized to
look like the following. However, I don't know the right way to do
that in Java.
<?xml version='1.0' encoding='UTF-8'?>
<SOAP-ENV:Envelope
xmlns:SOAP-ENV='http://schemas.xmlsoap.org/soap/envelope/'
xmlns:xsi='http://www.w3.org/1999/XMLSchema-instance'
xmlns:xsd='http://www.w3.org/1999/XMLSchema'>
|
by: Frederick Gotham |
last post by:
Back in the day, if you wanted a function to be self-contained within a
translation unit, you defined the function as "static".
If there were an external linkage function by the same name residing in a
different translation unit, then the current translation unit was simply
oblivious to it and had no way of accessing it. Any time the function
name was mentioned in the current translation unit, it referred to the
"static" one which...
|
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 usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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 into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |