Get Warning LNK4222 , How to fix it ?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • headshot
    New Member
    • Jul 2012
    • 5

    #1

    Get Warning LNK4222 , How to fix it ?

    Hello Everybody
    I have a project ALT with C++ program.
    After build , I get some of warning in file Bhonew.def


    I have read this reference http://msdn.microsoft.com/en-us/libr...=vs.71%29.aspx
    Code:
      Open the project's Property Pages dialog box. For details, see Setting Visual C++ Project Properties.
        Click the Linker folder.
        Click the Command Line property page.
        Type the option into the Additional Options box.
    But i don`t known how to input at here
    Can you help me ?Thank you
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    Your export functions are always located by name using GetProcAddress. Remove your export ordinals from the DEF file.

    Read: http://msdn.microsoft.com/en-us/libr...(v=vs.71).aspx

    Comment

    • headshot
      New Member
      • Jul 2012
      • 5

      #3
      hi weaknessforcats
      Follow http://msdn.microsoft.com/en-us/libr...=vs.71%29.aspx
      Should i do it ? .
      Code:
      ; BhoNew.def : Declares the module parameters.
      
      LIBRARY      "BhoNew.DLL"
      
      EXPORTS
      	DllCanUnloadNow  
      	DllGetClassObject 
      	DllRegisterServer   
      	DllUnregisterServer

      Comment

      • weaknessforcats
        Recognized Expert Expert
        • Mar 2007
        • 9214

        #4
        So you are creating BhoNew.DLL?

        Then to use it in your application project just call LoadLibrary followed by GetProcAddress for these functions and then call the function sing the returned function pointer.


        Here's an example:
        Code:
        #include <iostream>
        using namespace std;
        
        #include <windows.h>
        
        
        
        int main()
        {
        	
        	
        
        	cout << "Calling functions from a dll" << endl;
        
        	//First, load the dll into memory
        	HMODULE theDll = LoadLibrary("C:\\Scratch\\ClassDemos\\ADll\\Debug\\ADll.dll");
        	if (!theDll)
        	{
        		cout << "The dll failed to load" << endl;
        		return 1;
        	}
        
        	//Second, get the address of the desried function from the dll
        	FARPROC addr = GetProcAddress(theDll, "DisplayFromDll");
        	if (!addr)
        	{
        		
        		//Look up the error in the system errors list
        		unsigned int what = GetLastError();
        		if (what == ERROR_PROC_NOT_FOUND)
        		{
        			cout << "Function not found in the dll" << endl;
        		}
        		else
        		{
        			cout << "Error: " << what << endl;
        		}
        		return 2;
        	}
            cout << "The function has been located in the dll" << endl;
        	//Declare a function pointer that can accept the address of the function.
        	//You will need to know the function prototype to do this.
        	//Dll function prototypes should be provided by the vendor of the dll
        	void (__stdcall *DisplayFromDll)();
        	//Type-cast the address returned from GetProcAddress to the function pointer type
        	DisplayFromDll = reinterpret_cast<void (__stdcall *)()>  (addr);
        	//Now use the function pointer to call the function:
            DisplayFromDll();
        
        	//If you don't use a .def file in the dll, you must use the mangled name
        	//Second, get the address of the desried function from the dll
        	addr = GetProcAddress(theDll, "AreaOfSquare");
        	if (!addr)
        	{
        		
        		//Look up the error in the system errors list
        		unsigned int what = GetLastError();
        		if (what == ERROR_PROC_NOT_FOUND)
        		{
        			cout << "Function not found in the dll" << endl;
        		}
        		else
        		{
        			cout << "Error: " << what << endl;
        		}
        		return 2;
        	}
        
        	cout << "The function has been located in the dll" << endl;
        	//Declare a function pointer that can accept the address of the function.
        	//You will need to know the function prototype to do this.
        	//Dll function prototypes should be provided by the vendor of the dll
        	int (__stdcall *AreaOfSquare)(int, int);
        	//Type-cast the address returned from GetProcAddress to the function pointer type
        	AreaOfSquare = reinterpret_cast<int (__stdcall*)(int,int)>  (addr);
        	//Now use the function pointer to call the function:
            cout << "The area of a 6x8 square is " << AreaOfSquare(6,8) << endl;;
        
        	//Finally, unload the dll from memory
        	FreeLibrary(theDll);
        
        	return 0;
        }

        Comment

        Working...