Thread: Reg Problem with creating a DLL

  1. #1
    Registered User
    Join Date
    Nov 2009
    Posts
    2

    Reg Problem with creating a DLL

    Dear All,

    I am trying to create a DLL file for some testing works related to my field. I am using Dev-C++ 4.9.9.2 for doing this. This DLL will be used by a VECTOR Software(CAN DIVA). I am using a template given by Vector.But when I compile it I keep getting the error message "Function Definition is marked DLL Import. "
    As I am a newbie can any please help me out.

    I have pasted the .cpp & .h file below.

    Code:
    //****************************************************************************************
    //   File name: KeyGenAlgo.h
    // Description: Abstract base class defines the interface for the key generation algorithm
    //        Date: 2003-07-17
    //   Copyright: Vector Informatik GmbH - 2003
    //****************************************************************************************
    
    #ifndef KEY_GEN_ALGO_INTERFACE_H
    #define KEY_GEN_ALGO_INTERFACE_H
    
    #if _MSC_VER > 1000
    #pragma once
    #endif
    
    
    #ifdef KEYGENALGO_EXPORTS
    #define KEYGENALGO_API extern "C" __declspec(dllexport)
    #else
    #define KEYGENALGO_API __declspec(dllimport)
    #endif
    
    
    
    enum VKeyGenResultEx
    {
      KGRE_Ok = 0,
      KGRE_BufferToSmall = 1,
      KGRE_SecurityLevelInvalid = 2,
      KGRE_VariantInvalid = 3,
      KGRE_UnspecifiedError = 4
    };
    
    
    // The client has to provide a keyArray buffer and has to transfer this buffer - 
    // including its size - to the GenerateKey method. The method checks, if the size is
    // sufficient. The client can discover the required size by examinig the service used
    // transfer the key to the ECU.
    // Returns false if the key could not be generated:
    //  -> keyArraySize to small
    //  -> generation for specified security level not possible
    //  -> variant unknown
    KEYGENALGO_API VKeyGenResultEx GenerateKeyEx(
       const unsigned char* iSeedArray, unsigned short iSeedArraySize,
       const unsigned int iSecurityLevel, const char* iVariant,
       unsigned char* ioKeyArray, unsigned int iKeyArraySize, unsigned int& oSize);
    
    #endif // KEY_GEN_ALGO_INTERFACE_H
    //*********************************************************************************************
    //*********************************************************************************************
    
    // KeyGeneration.cpp : Defines the entry point for the DLL application.
    
    
    #include <windows.h>
    #include "KeyGenAlgoInterfaceEx.h"
    
    
    
    BOOL APIENTRY DllMain( HANDLE hModule, 
                           DWORD  ul_reason_for_call, 
                           LPVOID lpReserved
    					 )
    {     
        return TRUE;
    }
    
    
    KEYGENALGO_API VKeyGenResultEx GenerateKeyEx(
       const unsigned char* iSeedArray, unsigned short iSeedArraySize,
       const unsigned int iSecurityLevel, const char* iVariant,
       unsigned char* ioKeyArray, unsigned int iKeyArraySize, unsigned int& oSize)
      //the constant key 0x22 0x32 is returned by this example 
    { 
      ioKeyArray[0] = 0x22;
      ioKeyArray[1] = 0x32;
      oSize = iSeedArraySize;  
    return KGRE_Ok;
    }
    This is the error message that I get

    22 C:\Documents and Settings\Administrator\Desktop\Dev C\DLL\1\KeyGeneration.cpp function `VKeyGenResultEx GenerateKeyEx(const unsigned char*, short unsigned int, unsigned int, const char*, unsigned char*, unsigned int, unsigned int&)' definition is marked dllimport.

    Thanks

  2. #2
    Registered User
    Join Date
    Jan 2008
    Posts
    290
    On a quick glance, it looks to me like you are trying to compile a library that is meant to be used by other code.

    Unfortunately, in the code module that implements the library you aren't defining the proper macro to specify that you will be EXPORTING the functions that you're compiling.

    Looks to me like you just need to define the KEYGENALGO_EXPORTS macro in KeyGeneration.cpp:

    Code:
    #include <windows.h>
    
    #define KEYGENALGO_EXPORTS
    #include "KeyGenAlgoInterfaceEx.h"

  3. #3
    Registered User
    Join Date
    Nov 2009
    Posts
    2

    Reg Problem with creating a DLL

    Kool....
    adding that solved the issue.....
    thanks a lot......

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Trying to make C++ DLL, got a problem with hWnd
    By Ragoune in forum C++ Programming
    Replies: 8
    Last Post: 03-11-2009, 03:24 PM
  2. Problem about Creating structure
    By albert3721 in forum C Programming
    Replies: 3
    Last Post: 06-05-2007, 07:33 PM
  3. Creating DLL in DevC++
    By kkchennai in forum C Programming
    Replies: 6
    Last Post: 03-17-2006, 05:30 AM
  4. VCL and DLL class problem
    By borland_man in forum C++ Programming
    Replies: 1
    Last Post: 02-13-2002, 11:07 AM