473,811 Members | 2,850 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

problems using dllimport

diggityduncs (Programmer) Nov 13, 2003
Hello,

I'm tring to use a win32/api dll in c#

The vendor I received the dll from doesn't know anything
about .net

I received two files
ACGAPI.DLL +
ACGAPI.LIB

and some example source code

Declaration:

Visual C/C++

extern "C" __declspec(dlli mport) int __stdcall
V5_CalculateAct ivationCode(LPS TR lpSiteCode, LPSTR
lpProgramID, DWORD CustomFeatures, LPSTR
lpActivationCod e, LPSTR lpRemovalCode)

Visual basic:

Declare Function V5_CalculateIni tCode Lib "ACGAPI.DLL "
Alias "_V5_CalculateI nitCode@20" (ByVal SiteCode As
String, ByVal ProgramID As String, ByVal CustomFeatures
As Long, ByVal ActivationCode As String, ByVal
RemovalCode As String) As Long

Parameters:

(in)

LPSTR lpSiteCode - Pointer to Site code string (8
characters long)

LPSTR lpProgramID - Pointer to ProgramID (24 characters
long)

DWORD CustomFeatures - Status of custom features (set to
0 if custom features are not required)

(out)
LPSTR lpActivationCod e - Pointer to buffer for activation
code (should be at least 36 character long)

LPSTR lpRemovalCode - Pointer to buffer for removal code
(should be at least 9 character long)

This is code I came up with

using System.Runtime. InteropServices ;

[DllImport("acga pi.dll")]
private static extern long V5_CalculateAct ivationCode
(string SiteCode,string ProgramID,long
CustomFeatures, string ActivationCode, string RemovalCode);

I get the following error when I run the code

Unable to find an entry point named
V5_CalculateAct ivationCode in DLL acgapi.dll
I believe it may something to do with the .lib file. In
the old visual studio you could add the .lib file in the
project settings

http://www.codeproject.com/audio/speech.asp?print=true

but I'm not sure where you do this VS.net
Any help here would greatly be appreciated,
Thanks,
Paul
Nov 15 '05 #1
2 2367
You don't need the lib file, you need an entry point:
[DllImport("acga pi.dll", EntryPoint="_V5 _CalculateInitC ode@20")]
private static extern int V5_CalculateAct ivationCode
(string SiteCode,string ProgramID,int
CustomFeatures, string ActivationCode, string RemovalCode);
Note that longs in vb6 are ints in c#.

--
Michael Culley
"Paul Duncan" <di**********@h otmail.com> wrote in message news:05******** *************** *****@phx.gbl.. . diggityduncs (Programmer) Nov 13, 2003
Hello,

I'm tring to use a win32/api dll in c#

The vendor I received the dll from doesn't know anything
about .net

I received two files
ACGAPI.DLL +
ACGAPI.LIB

and some example source code

Declaration:

Visual C/C++

extern "C" __declspec(dlli mport) int __stdcall
V5_CalculateAct ivationCode(LPS TR lpSiteCode, LPSTR
lpProgramID, DWORD CustomFeatures, LPSTR
lpActivationCod e, LPSTR lpRemovalCode)

Visual basic:

Declare Function V5_CalculateIni tCode Lib "ACGAPI.DLL "
Alias "_V5_CalculateI nitCode@20" (ByVal SiteCode As
String, ByVal ProgramID As String, ByVal CustomFeatures
As Long, ByVal ActivationCode As String, ByVal
RemovalCode As String) As Long

Parameters:

(in)

LPSTR lpSiteCode - Pointer to Site code string (8
characters long)

LPSTR lpProgramID - Pointer to ProgramID (24 characters
long)

DWORD CustomFeatures - Status of custom features (set to
0 if custom features are not required)

(out)
LPSTR lpActivationCod e - Pointer to buffer for activation
code (should be at least 36 character long)

LPSTR lpRemovalCode - Pointer to buffer for removal code
(should be at least 9 character long)

This is code I came up with

using System.Runtime. InteropServices ;

[DllImport("acga pi.dll")]
private static extern long V5_CalculateAct ivationCode
(string SiteCode,string ProgramID,long
CustomFeatures, string ActivationCode, string RemovalCode);

I get the following error when I run the code

Unable to find an entry point named
V5_CalculateAct ivationCode in DLL acgapi.dll
I believe it may something to do with the .lib file. In
the old visual studio you could add the .lib file in the
project settings

http://www.codeproject.com/audio/speech.asp?print=true

but I'm not sure where you do this VS.net
Any help here would greatly be appreciated,
Thanks,
Paul

Nov 15 '05 #2

Hi Paul,

The lib files are for the Visual C++ to static link the dll files.
While the interop the dll use the dynamic call, it does not need the lib
files.
For more information about lib files, you can check:
http://msdn.microsoft.com/library/de...us/vccore/html
/_core_lib_refer ence.asp

I think you should check the return type of your function. Also, you can
use EntryPoint field to specify a function entry.

Hope this helps,
Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

--------------------
| Content-Class: urn:content-classes:message
| From: "Paul Duncan" <di**********@h otmail.com>
| Sender: "Paul Duncan" <di**********@h otmail.com>
| Subject: problems using dllimport
| Date: Thu, 13 Nov 2003 18:59:33 -0800
| Lines: 80
| Message-ID: <05************ *************** *@phx.gbl>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="iso-8859-1"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
| Thread-Index: AcOqW1Rxckc60Mc 1QW238Rsb+Lb22g ==
| Newsgroups: microsoft.publi c.dotnet.langua ges.csharp
| Path: cpmsftngxa06.ph x.gbl
| Xref: cpmsftngxa06.ph x.gbl microsoft.publi c.dotnet.langua ges.csharp:1992 36
| NNTP-Posting-Host: TK2MSFTNGXA13 10.40.1.165
| X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.csharp
|
| diggityduncs (Programmer) Nov 13, 2003
| Hello,
|
| I'm tring to use a win32/api dll in c#
|
| The vendor I received the dll from doesn't know anything
| about .net
|
| I received two files
| ACGAPI.DLL +
| ACGAPI.LIB
|
| and some example source code
|
| Declaration:
|
| Visual C/C++
|
| extern "C" __declspec(dlli mport) int __stdcall
| V5_CalculateAct ivationCode(LPS TR lpSiteCode, LPSTR
| lpProgramID, DWORD CustomFeatures, LPSTR
| lpActivationCod e, LPSTR lpRemovalCode)
|
| Visual basic:
|
| Declare Function V5_CalculateIni tCode Lib "ACGAPI.DLL "
| Alias "_V5_CalculateI nitCode@20" (ByVal SiteCode As
| String, ByVal ProgramID As String, ByVal CustomFeatures
| As Long, ByVal ActivationCode As String, ByVal
| RemovalCode As String) As Long
|
| Parameters:
|
| (in)
|
| LPSTR lpSiteCode - Pointer to Site code string (8
| characters long)
|
| LPSTR lpProgramID - Pointer to ProgramID (24 characters
| long)
|
| DWORD CustomFeatures - Status of custom features (set to
| 0 if custom features are not required)
|
| (out)
| LPSTR lpActivationCod e - Pointer to buffer for activation
| code (should be at least 36 character long)
|
| LPSTR lpRemovalCode - Pointer to buffer for removal code
| (should be at least 9 character long)
|
|
|
| This is code I came up with
|
| using System.Runtime. InteropServices ;
|
| [DllImport("acga pi.dll")]
| private static extern long V5_CalculateAct ivationCode
| (string SiteCode,string ProgramID,long
| CustomFeatures, string ActivationCode, string RemovalCode);
|
| I get the following error when I run the code
|
| Unable to find an entry point named
| V5_CalculateAct ivationCode in DLL acgapi.dll
|
|
| I believe it may something to do with the .lib file. In
| the old visual studio you could add the .lib file in the
| project settings
|
| http://www.codeproject.com/audio/speech.asp?print=true
|
| but I'm not sure where you do this VS.net
|
|
| Any help here would greatly be appreciated,
| Thanks,
| Paul
|

Nov 15 '05 #3

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

Similar topics

4
4749
by: Umesh | last post by:
Hi all I am trying to change the printer(like paper source ,etc) setting in C#. But i am unable to do it. I am not sure how to do it. should i have to use WIN API like Openprinter , getprinter , setprinter . I did try with PrinterSetting.setHDevMode but it does not work. Its their is a simple way to change printersetting. thanks umesh.
5
6732
by: JackRazz | last post by:
I'm having problems trying to call GetMonitorInfo. I believe the problem has something to do with the szDeviceName. Passing a MonitorInfo struct works fine. I added the szDeviceName and the struct is filled with garbage. What am I doing wrong?? Thanks - JackRazz Pretty version of this snippet is here: http://rafb.net/paste/results/M3114698.html
4
7714
by: Jerry | last post by:
I am trying to read a physical sector off of the disk (the boot sector for drive C:) from C#. I have no problems doing it from a C/C++ application using the Win32 API CreateFile and ReadFile. However, when I attempt to use PInvoke to do the very same thing in C# the data read in is somehow being altered from what is on disk. Several of the bytes are being changed from their original value to 0x3f!?!?! Anyone have any ideas as to what I...
1
5095
by: redneon | last post by:
I'm trying to add another button to a window's title bar to use as a "keep this window on top" button. I've managed to draw the button using the code below (C#) but I'm having a couple of other problems... .... private bool buttonChecked = false; private int buttonSize = 16; private int buttonX = 226; private int buttonY = 6;
0
2484
by: Claire | last post by:
Hi Ive been using Mattias Sjögren's example at http://www.msjogren.net/dotnet/eng/samples/dotnet_dynpinvoke.asp to load an unmanaged 3rd party dll dynamically when my object is created. Calling the "CreateDllAssembly" function below does this. When my wrapper is disposed of, I want the dll to be unloaded from memory. See the "dispose" function below. All seems to work ok on the first instance of my wrapper class. (I only
2
1132
by: bobnotbob | last post by:
I have created an application and am trying to call functions from a previously existing dll. I can call some functions fine, but I get a link error an when I try to call any function that takes either an LPCTSTR or wchar_tas a parameter. I am using C++ and Visual Studio .NET. Here's two functions that cause me problems: void CADAPICALL JuncFunc9(LPCTSTR aaa); void CADAPICALL JuncFunc10( wchar_t * aaa);
9
1713
by: The Grim Reaper | last post by:
Dear Gurus... (Sorry to cross post... but...) I have a dire problem - been working on this for days now. It's the undocumented API's for NTDLL.dll - namely NtOpenSection, NtMapViewOfSection, NtUnmapViewOfSection, CloseHandle and CopyMemory. Code listing 1 shows the existing VB6 code, which works perfectly. However, on upgrading the code to .NET, I am getting no value returned to vPhysicalMemory - indicating that the NtOpenSection call...
1
8084
by: Thomas Due | last post by:
Hi, I manage an rather old application in which we have some fairly complex (ugly) Delphi code. This is Delphi 6 we're talking about. Among all this Delphi code there is method for formating a print layout for slip printers. Pass a few parameters to this method and it returns a Delphi string which contains the entire slip, ready for sending to the slip printer. Now, we're slowly migrating to .NET and am in need of printing this slip...
14
3797
by: Mohamed Mansour | last post by:
Hey there, this will be somewhat a long post, but any response is appreciated! I have done many PInvoke in the past from C++ to C#, but I did PInvoke within C# not C++/CLI. Can someone explain more why C++/CLI would be better to PInvoke than doing the PInvoke in C#? Because, usually in C# as you already know we use DLLImport and extern
0
9607
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,...
0
10663
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10401
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10138
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7676
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5567
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...
0
5704
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4357
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
2
3881
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.