Click here to Skip to main content
15,892,927 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have created the dll in MFC named as CalcDLL. I have added the add class to that dll project in that i have written the code for mathematical operations like add,subtract,multiplication,division.
After I have created the new project with dialogue based MFC application. In that for calling i have added the code for addition.
For adding CalcDLL.dll to that main project in project menu -> properties->configuration properties->linker->input->additional dependencies i have added the dll path. But it is showing
Error 1 error LNK1107: invalid or corrupt file: cannot read at 0x328
How to resolve this error can anyone explain to me and i need to use only with .dll not with adding .lib

What I have tried:

In main project:
void CCalciMainDlg::OnBnClickedAdd()
{

CAdd a;
Num1 = GetDlgItemInt(IDC_EDIT_NUM1);
Num2 = GetDlgItemInt(IDC_EDIT_NUM2);
int opt = 1;
Output = a.operation(Num1, Num2,opt);

SetDlgItemInt(IDC_EDIT_OUTPUT, Output);
}

In Dll project:CalcDLL
ADD Class:Add.cpp

int CAdd::operation(int nNum1, int nNum2,int opt)
{
int result;
switch (opt)
{
case 1:
result = nNum1 + nNum2;
break;
case 2:
result = nNum1 - nNum2;
break;
case 3:
result = nNum1 * nNum2;
break;
case 4:
result = nNum1 / nNum2;
break;
}
return result;
}
Posted
Updated 14-Nov-17 23:38pm

You need to add the .lib file to your linker options, not the dll. The .LIB file is used by the linker to satisfy the references to your DLL functions. The DLL itself will be loaded at run time when the application starts.
 
Share this answer
 
Comments
Member 13522230 15-Nov-17 7:08am    
Thank you for your help but with adding .lib in linker properties. I am getting system error i.e., The program can't start because CalcDLL.dll is missing from your computer.
Can you tell for this issue.
Richard MacCutchan 15-Nov-17 7:57am    
Where is CalcDLL.dll?
You have to add the lib file to your projects settings or use a pragma directive in one of your source files (comment (C-C++)[^]):
C++
#pragma comment(lib, "[path\]libname")
When creating a DLL project, the corresponding lib file is created and placed together with the DLL in the project build output directory.

If you don't want to use a lib file, you can load the DLL during runtime with the LoadLibrary function (Windows)[^]. But then you have to declare prototypes for the exported functions and get the function pointers with the GetProcAddress function (Windows)[^].
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900