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

  • Thread starter Thread starter Dave Griffin
  • Start date Start date
D

Dave Griffin

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.
 
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.
 
Dave Griffin said:
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/d...-us/vccore98/html/_core_export_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/d..._core_export_from_a_dll_using_..def_files.asp



David
 
David Browne said:
Dave Griffin said:
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/d...-us/vccore98/html/_core_export_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/d..._core_export_from_a_dll_using_..def_files.asp



David

Thanks, I'll try this. So far so good.
 
Back
Top