473,511 Members | 15,852 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Unmanaged DLL -- How can I create one in .NET 2003?

I have what I think is an "unmanaged DLL" that I access from within C#
using the construction:

[DllImport("sbslib32.dll")]
public static extern ushort sbs_init_device(ushort DevNum,
ushort queue_length, ushort bsm_length,
SBS1553Classes.SBS_FIRMWARE_SOURCE firmware_source);

There are no object oriented constructions here and the code is
actually C (not C++). I would like to create a "phony" version of this
DLL for use on our desktop machines (where the hardware this DLL uses
is not present) but I don't know how to do it in .NET or if it's even
possible. I would like to install it on the desktop and then use my
own implementation (my phony DLL) to pretend to feed data to my
program in order to construct non-trivial tests of throughput.

Is there a way to do this, and if so, can you point me to an example?
Thanks.
Nov 16 '05 #1
3 2126
Dave,

Well, you wouldn't do it in .NET per se, but you can create it in Visual
Studio .NET.

Basically, you want a win32 project. When creating a new project, check
the project templates for one with that name. It will then lead you through
the steps of creating a dll.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Dave Griffin" <ca***********@yahoo.com> wrote in message
news:45*************************@posting.google.co m...
I have what I think is an "unmanaged DLL" that I access from within C#
using the construction:

[DllImport("sbslib32.dll")]
public static extern ushort sbs_init_device(ushort DevNum,
ushort queue_length, ushort bsm_length,
SBS1553Classes.SBS_FIRMWARE_SOURCE firmware_source);

There are no object oriented constructions here and the code is
actually C (not C++). I would like to create a "phony" version of this
DLL for use on our desktop machines (where the hardware this DLL uses
is not present) but I don't know how to do it in .NET or if it's even
possible. I would like to install it on the desktop and then use my
own implementation (my phony DLL) to pretend to feed data to my
program in order to construct non-trivial tests of throughput.

Is there a way to do this, and if so, can you point me to an example?
Thanks.

Nov 16 '05 #2

"Dave Griffin" <ca***********@yahoo.com> wrote in message
news:45*************************@posting.google.co m...
I have what I think is an "unmanaged DLL" that I access from within C#
using the construction:

[DllImport("sbslib32.dll")]
public static extern ushort sbs_init_device(ushort DevNum,
ushort queue_length, ushort bsm_length,
SBS1553Classes.SBS_FIRMWARE_SOURCE firmware_source);

There are no object oriented constructions here and the code is
actually C (not C++). I would like to create a "phony" version of this
DLL for use on our desktop machines (where the hardware this DLL uses
is not present) but I don't know how to do it in .NET or if it's even
possible. I would like to install it on the desktop and then use my
own implementation (my phony DLL) to pretend to feed data to my
program in order to construct non-trivial tests of throughput.

Is there a way to do this, and if so, can you point me to an example?

Sure

Visual Studio > New Project > Visual C++ Projects > Win32 Projects > Win32
Project
Brings up the "Win32 Application Wizard"
Change Application Settings > Application Type
Choose ApplicationType: DLL and Additional Options: Export Symbols

That will create a skeleton of an unmanaged DLL. In the [appname].h file
are the exports for the application, with examples of exporting a class,
variable and a function.

See generally

http://msdn.microsoft.com/library/de...from_a_dll.asp

Something like this:

struct SBS_FIRMWARE_SOURCE
{
int i;
};
extern "C" __declspec(dllexport)
unsigned short sbs_init_device(
unsigned short DevNum,
unsigned short queue_length,
unsigned short bsm_length,
SBS_FIRMWARE_SOURCE firmware_source);

If the function in uses the cdecl calling convention. For stdcall use
extern "C" __declspec(dllexport)
unsigned short __stdcall sbs_init_device(
unsigned short DevNum,
unsigned short queue_length,
unsigned short bsm_length,
SBS_FIRMWARE_SOURCE firmware_source);

But in the case of stdcall, you'll also need to use a .def file to name the
export because the compiler will name the exported function
"_sbs_init_device".

http://msdn.microsoft.com/library/de....def_files.asp

David

Nov 16 '05 #3
"David Browne" <davidbaxterbrowne no potted me**@hotmail.com> wrote in message news:<Og**************@TK2MSFTNGP11.phx.gbl>...
"Dave Griffin" <ca***********@yahoo.com> wrote in message
news:45*************************@posting.google.co m...
I have what I think is an "unmanaged DLL" that I access from within C#
using the construction:

[DllImport("sbslib32.dll")]
public static extern ushort sbs_init_device(ushort DevNum,
ushort queue_length, ushort bsm_length,
SBS1553Classes.SBS_FIRMWARE_SOURCE firmware_source);

There are no object oriented constructions here and the code is
actually C (not C++). I would like to create a "phony" version of this
DLL for use on our desktop machines (where the hardware this DLL uses
is not present) but I don't know how to do it in .NET or if it's even
possible. I would like to install it on the desktop and then use my
own implementation (my phony DLL) to pretend to feed data to my
program in order to construct non-trivial tests of throughput.

Is there a way to do this, and if so, can you point me to an example?

Sure

Visual Studio > New Project > Visual C++ Projects > Win32 Projects > Win32
Project
Brings up the "Win32 Application Wizard"
Change Application Settings > Application Type
Choose ApplicationType: DLL and Additional Options: Export Symbols

That will create a skeleton of an unmanaged DLL. In the [appname].h file
are the exports for the application, with examples of exporting a class,
variable and a function.

See generally

http://msdn.microsoft.com/library/de...from_a_dll.asp

Something like this:

struct SBS_FIRMWARE_SOURCE
{
int i;
};
extern "C" __declspec(dllexport)
unsigned short sbs_init_device(
unsigned short DevNum,
unsigned short queue_length,
unsigned short bsm_length,
SBS_FIRMWARE_SOURCE firmware_source);

If the function in uses the cdecl calling convention. For stdcall use
extern "C" __declspec(dllexport)
unsigned short __stdcall sbs_init_device(
unsigned short DevNum,
unsigned short queue_length,
unsigned short bsm_length,
SBS_FIRMWARE_SOURCE firmware_source);

But in the case of stdcall, you'll also need to use a .def file to name the
export because the compiler will name the exported function
"_sbs_init_device".

http://msdn.microsoft.com/library/de....def_files.asp

David


Thanks, I'll try this. So far so good.
Nov 16 '05 #4

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

Similar topics

7
3287
by: Timothy Shih | last post by:
Hi, I am trying to figure out how to use unmanaged code using P/Invoke. I wrote a simple function which takes in 2 buffers (one a byte buffer, one a char buffer) and copies the contents of the byte...
4
2148
by: | last post by:
I am stuck in a situation and I do believe that this should work, but it doesn't. I have a unmanaged dll, that uses MFC. This works great. Now I recompile the unmanaged dll so it contains...
5
1811
by: Anthony Evans | last post by:
Greetings I'm using VC++.NET to create a class library. The class library contains managed classes that wrap legacy unmanaged classes by the same name. I use regasm to register the DLL for...
0
957
by: Kristof Thys via .NET 247 | last post by:
Hello, I've been struggling for weeks with this problem, I hope I find some help here... To start, in our company, we have a large existing c++ project (native code, unmanaged c++) The...
7
1720
by: Kristof Thys via .NET 247 | last post by:
Post a new message to microsoft.public.dotnet.languages.vc http://www.dotnet247.com/247reference/default.aspx Hello, I've been struggling for weeks with this problem, I hope I find some...
4
1152
by: Fredrik Wahlgren | last post by:
hi I have apet aproject that i created a long time ago and I now want to make part of it managed. This is a dtabase application s I want to create a class in which I wrap ADO.NET. The design is...
0
977
by: Adam M. Rosenzweig | last post by:
Hello, I am having a problem getting a particular web service to work on a win 2003 server. This web service does work on my XP box. The web service is written in VB.NET, and uses a declare...
1
1030
by: Bill S. | last post by:
Hi, I'm trying to create an unmanaged instance within a managed object. In the one module, I've constructed an unmanaged class that makes a lot of API calls. It compiles with no errors. In the...
9
3100
by: Amit Dedhia | last post by:
Hi All I have a VC++ 2005 MFC application with all classes defined as unmanaged classes. I want to write my application data in xml format. Since ADO.NET has buit in functions available for...
0
7242
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,...
0
7353
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,...
0
7418
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7075
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...
0
5662
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,...
1
5063
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...
0
4737
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...
0
3222
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...
0
3212
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.