problems using dllimport

  • Thread starter Thread starter Paul Duncan
  • Start date Start date
P

Paul Duncan

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(dllimport) int __stdcall
V5_CalculateActivationCode(LPSTR lpSiteCode, LPSTR
lpProgramID, DWORD CustomFeatures, LPSTR
lpActivationCode, LPSTR lpRemovalCode)

Visual basic:

Declare Function V5_CalculateInitCode Lib "ACGAPI.DLL"
Alias "_V5_CalculateInitCode@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 lpActivationCode - 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("acgapi.dll")]
private static extern long V5_CalculateActivationCode
(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_CalculateActivationCode 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
 
You don't need the lib file, you need an entry point:
[DllImport("acgapi.dll", EntryPoint="_V5_CalculateInitCode@20")]
private static extern int V5_CalculateActivationCode
(string SiteCode,string ProgramID,int
CustomFeatures,string ActivationCode,string RemovalCode);

Note that longs in vb6 are ints in c#.

--
Michael Culley


Paul Duncan said:
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(dllimport) int __stdcall
V5_CalculateActivationCode(LPSTR lpSiteCode, LPSTR
lpProgramID, DWORD CustomFeatures, LPSTR
lpActivationCode, LPSTR lpRemovalCode)

Visual basic:

Declare Function V5_CalculateInitCode Lib "ACGAPI.DLL"
Alias "_V5_CalculateInitCode@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 lpActivationCode - 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("acgapi.dll")]
private static extern long V5_CalculateActivationCode
(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_CalculateActivationCode 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
 
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/default.asp?url=/library/en-us/vccore/html
/_core_lib_reference.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" <[email protected]>
| Sender: "Paul Duncan" <[email protected]>
| Subject: problems using dllimport
| Date: Thu, 13 Nov 2003 18:59:33 -0800
| Lines: 80
| Message-ID: <[email protected]>
| 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: AcOqW1Rxckc60Mc1QW238Rsb+Lb22g==
| Newsgroups: microsoft.public.dotnet.languages.csharp
| Path: cpmsftngxa06.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.csharp:199236
| NNTP-Posting-Host: TK2MSFTNGXA13 10.40.1.165
| X-Tomcat-NG: microsoft.public.dotnet.languages.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(dllimport) int __stdcall
| V5_CalculateActivationCode(LPSTR lpSiteCode, LPSTR
| lpProgramID, DWORD CustomFeatures, LPSTR
| lpActivationCode, LPSTR lpRemovalCode)
|
| Visual basic:
|
| Declare Function V5_CalculateInitCode Lib "ACGAPI.DLL"
| Alias "_V5_CalculateInitCode@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 lpActivationCode - 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("acgapi.dll")]
| private static extern long V5_CalculateActivationCode
| (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_CalculateActivationCode 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
|
 
Back
Top