Reference error in DLL

Asked

Viewed 241 times

5

I am creating a DLL that needs to export 11 CEN/XFS functions, but there is a function that consumes a header file. I think the mistake is in consuming a method from a header that is not stated in my scope, someone to help ?

This dll will communicate with XFS Manager.

My code is this (My DLL - dllmain.cpp):

HRESULT WINAPI WFPOpen ( HSERVICE hService, LPSTR lpszLogicalName, HAPP hApp, LPSTR lpszAppID, DWORD dwTraceLevel, DWORD dwTimeOut, HWND hWnd, REQUESTID ReqID, HPROVIDER hProvider, DWORD dwSPIVersionsRequired, LPWFSVERSION lpSPIVersion, DWORD dwSrvcVersionsRequired, LPWFSVERSION lpSrvcVersion)
{

printf("INTO WFPOpen");
WFSRESULT * lpWFSResult;
HRESULT result;
SYSTEMTIME st; 
HRESULT rt;
GetSystemTime(&st); 

//o erro ocorre aki
result = WFMAllocateBuffer(sizeof(WFSRESULT), WFS_MEM_ZEROINIT, (void**)&lpWFSResult);

if(result!=WFS_SUCCESS){
        return WFS_ERR_INTERNAL_ERROR; 
}                    

return WFS_SUCCESS;
}

Header file (XFSADMIN. H):

HRESULT extern WINAPI WFMAllocateBuffer(ULONG ulSize, ULONG ulFlags, LPVOID * lppvData);

My dll. h (11 methods that will be exported)

class DLLIMPORT DllClass
{
public:
    HRESULT WINAPI WFPCancelAsyncRequest (HSERVICE hService, REQUESTID RequestID);
    HRESULT WINAPI WFPClose (HSERVICE hService, HWND hWnd, REQUESTID ReqID);
    HRESULT WINAPI WFPDeregister (HSERVICE hService, DWORD dwEventClass, HWND hWndReg, HWND hWnd, REQUESTID ReqID);
    HRESULT WINAPI WFPExecute (HSERVICE hService, DWORD dwCommand, LPVOID lpCmdData, DWORD dwTimeOut, HWND hWnd, REQUESTID ReqID);
    HRESULT WINAPI WFPGetInfo (HSERVICE hService, DWORD dwCategory, LPVOID lpQueryDetails, DWORD dwTimeOut, HWND hWnd, REQUESTID ReqID);
    HRESULT WINAPI WFPLock (HSERVICE hService, DWORD dwTimeOut, HWND hWnd, REQUESTID ReqID);
    HRESULT WINAPI WFPOpen (HSERVICE hService, LPSTR lpszLogicalName, HAPP hApp, LPSTR lpszAppID, DWORD dwTraceLevel, DWORD dwTimeOut, HWND hWnd, REQUESTID ReqID, HPROVIDER hProvider, DWORD dwSPIVersionsRequired, LPWFSVERSION lpSPIVersion, DWORD dwSrvcVersionsRequired, LPWFSVERSION lpSrvcVersion);
    HRESULT WINAPI WFPRegister (HSERVICE hService,  DWORD dwEventClass, HWND hWndReg, HWND hWnd, REQUESTID ReqID);
    HRESULT WINAPI WFPSetTraceLevel (HSERVICE hService, DWORD dwTraceLevel);
    HRESULT WINAPI WFPUnloadService ();
    HRESULT WINAPI WFPUnlock (HSERVICE hService, HWND hWnd, REQUESTID ReqID);   
  };

However this error occurs when compiling the DLL.

inserir a descrição da imagem aqui

More precisely here:

$(CPP) -shared $(LINKOBJ) -o $(BIN) $(LIBS) -Wl,--output-def,$(DEF),--out-  implib,$(STATIC),--add-stdcall-alias
  • should be missing a lib in your project, maybe xfs_supp.lib

  • and where should I put ? at the root of the project I have tried and did not help.

  • that is missing a lib from XFS is practically right, and this lib "xfs_supp.lib" exports the function that is missing (Wfmaallocatebuffer)...you must set this lib as input in the link step of the build process dll...more than that can’t be said, without knowing the project

  • If I e-mail you what I am doing, could I have a look ? because I need to export this dll just for testing.

  • put more information about the project right here...other people will be able to look

  • I put more information.

  • you are using mingw or Cygwin (or something like that), does XFS libs work in that environment ? that I don’t know... anyway, looking at the link-editing line, is that in "$(LIBS)" the names of all the necessary libs ? Something else, this here "-Wl,-output-def,$(DEF),--out-implib,$(STATIC),-add-stdcall-alias" is weird, that space between "--out- implib" is just like that? Shouldn’t there be a comma in there ? I’m guessing here, but the suboptions of a "-Wl" option should be separated by a comma, not by space

  • Have you tried #pragma comment(lib, "xfs_supp.lib") in his dllmain.cpp?

Show 3 more comments

1 answer

1

To make this reference to the DLL, a lib is required. If when compiling your DLL, you can find some files, if you find a . a or . lib in your project it will be your Linker with your DLL.

Example: Who uses Dev-C++ or Visual Studio may appear some example of DLL.

#ifndef _DLL_H_
#define _DLL_H_

#if BUILDING_DLL
#define DLLIMPORT __declspec(dllexport)
#else
#define DLLIMPORT __declspec(dllimport)
#endif

class DLLIMPORT DllClass
{
    public:
        DllClass();
        virtual ~DllClass();
        void HelloWorld();
};

#endif

This is an example of Dev-C++ from dll.h. Note that the class receives the macro with __declspec(dllexport), as it is necessary to export the class and use it.

/* Replace "dll.h" with the name of your header */
#include "dll.h"
#include <windows.h>

DllClass::DllClass()
{

}

DllClass::~DllClass()
{

}

void DllClass::HelloWorld()
{
    MessageBox(0, "Hello World from DLL!\n","Hi",MB_ICONINFORMATION);
}

BOOL WINAPI DllMain(HINSTANCE hinstDLL,DWORD fdwReason,LPVOID lpvReserved)
{
    switch(fdwReason)
    {
        case DLL_PROCESS_ATTACH:
        {
            break;
        }
        case DLL_PROCESS_DETACH:
        {
            break;
        }
        case DLL_THREAD_ATTACH:
        {
            break;
        }
        case DLL_THREAD_DETACH:
        {
            break;
        }
    }
    
    /* Return TRUE on success, FALSE on failure */
    return TRUE;
}

This is dllmain.cpp and gets a function from WINAPI, remember that WINAPI is declared in windows.h. After compiling with all files including . h, you get certain files: inserir a descrição da imagem aqui

We have the source files. And we also have the . dll , . def and a . a After that depending on your IDE, you include the lib which is ". a" or ". lib" if it appears, in the Linker parameters (if you have) or in the compiler, in the case of Dev-C++ you have in project options the C and C++ Compiler and Linker part and a "Add Library" button and you add this in Linker.

inserir a descrição da imagem aqui

After inclusion you can create a header with the DLL functions:

#ifndef EXEMPLO_H
#define EXEMPLO_H

#define DLLIMPORT __declspec(dllexport)

class DLLIMPORT DllClass
{
    public:
        DllClass();
        virtual ~DllClass();
        void HelloWorld();
};

#endif

If you call a class or function without this DLL lib, it will not work. inserir a descrição da imagem aqui

If all goes well do this step by step and appear: inserir a descrição da imagem aqui

We can say that your program has the need for your DLL, it is a requirement. Finally placing the DLL next to the program. inserir a descrição da imagem aqui

I hope this DLL tutorial helps you.

that is missing a lib from XFS is practically right, and this lib "xfs_supp.lib" >exports the function that is missing (Wfmaallocatebuffer)...you should set up >this lib as input in the build process dll link step...more than >this can not be said, without knowing the project - zentrunix 23/01/17 at 14:42

That’s true, I had this case but with urlmon. h and if you use this XPS library, you need that lib. xfs_supp.lib can be found here.

  • This parameter in Makefile.win "implib,$(STATIC)" it causes the compiler to create the lib to link to the DLL and "-output-def,$(DEF)" creates a file with the references of functions such as this which was given error.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.