0

i'm really noob in C. I just need to compile a ANSI C source to get a dll. During compilation i get this error:

 C2491: 'SelectML': definition of dllimport function not allowed

Where SelectML is a public function with this definition:

int CALLINGCONV SelectML(WORD fid, int nSlot)
{
  WORD SW;
  int x;
  BYTE pSend[2];
  pSend[0]=(BYTE)((fid&0xff00)>>8);
  pSend[1]=(BYTE)(fid&0x00ff);
  x=SendAPDUML(hCards[nSlot],APDU_SELECT,2,0,pSend,0,&SW);
  if (x!=C_OK) return x;
  if (SW!=0x9000) return SW;
  return C_OK;
}

I'm sure the C source is good, maybe it is just a Visual Studio configuration...

This is another linked header:

#ifndef LIBSIAECARDT_H
#define LIBSIAECARDT_H

#ifdef __cplusplus
extern "C" {
#endif

#if !defined(USE_STDCALL)
#define USE_STDCALL 1
#endif

#ifdef _WIN32
#   if USE_STDCALL == 1
#       define CALLINGCONV_1 _stdcall
#   else 
#       define CALLINGCONV_1
#   endif

#   if defined(LIBSIAE_EXPORTS)
#       define LIBSIAEAPI __declspec(dllexport)
#   else
#       define LIBSIAEAPI __declspec(dllimport)
#   endif

#   define CALLINGCONV LIBSIAEAPI CALLINGCONV_1


#else // ! _WIN32
#   define CALLINGCONV 
#   define LIBSIAEAPI
#   define CALLINGCONV_1
typedef unsigned int UINT;
#endif  // _WIN32
Tobia
  • 9,165
  • 28
  • 114
  • 219

3 Answers3

0

Quoted in MSDN says it all. Do not define the function. Declaration is good. What you are doing here is defining SelectML which for sure is generating your C2491 Error.

Abhineet
  • 5,320
  • 1
  • 25
  • 43
  • I did not understand, in my ".c" file shoudn't be the declaration? – Tobia Sep 22 '12 at 08:52
  • Are you anywhere using "__declspec(dllimport)" keyword to implement a function???? – Abhineet Sep 22 '12 at 09:00
  • You can try reading this "http://stackoverflow.com/questions/8401359/c2491-stdnumpunct-elemid-definition-of-dllimport-static-data-member-n" – Abhineet Sep 22 '12 at 09:23
  • Microsoft defines the problem good:: http://support.microsoft.com/kb/815647 and for further reading exercise:: http://msdn.microsoft.com/en-us/library/kh1zw7z7(vs.71).aspx :-) – Abhineet Sep 22 '12 at 09:25
  • Post the definition for CALLINGCONV – Abhineet Sep 22 '12 at 09:33
0

It's common to have a macro like CALLINGCONV conditionally defined as __declspec(dllimport) or __declspec(dllexport) so that the same header file can be used in the library source and in the code using the library. Your build should probably define something that makes it use dllexport. Check how CALLINGCONV is defined or (preferably) consult any build documentation that came with the code.

Frank
  • 403
  • 2
  • 5
  • In this case it looks like you should define LIBSIAE_EXPORTS in your project's preprocessor settings – Frank Sep 22 '12 at 11:14
-1

Here's an alternative. Stop using MSVC. They explicitly dropped support for anything after C90. Use an actual C compiler for C code.

std''OrgnlDave
  • 3,912
  • 1
  • 25
  • 34