Error compiling after referencing a dll to an application - c++

I have created these projects separately and compiled successfully.
MyApp - MyApp.exe
Mydll - Mydll.dll 'It has s dialoguebox.Simple.
I want io include this dll to the app so that I can instantiate obj and call methods of the dll from the app. This is what I want to do.
Steps so far
I have put the name of lib in
Project Properties->Linker->Input->Addtional Dependencies
Tools->Option->Project and Solution->VC++->Library Files
put the path where the library files were (do I need to put the path of the debug folder where the dll/lib contains or I can copy the dll/lib to different folder and put this path?)
Tools->Option->Project and Solution->VC++->Include files
put the path of the header file of the dll/lib
All this done!
Compiler error
error C2065: 'IDD_DIALOG_CRINV' : undeclared identifier" IDD_DIALOG_CRINV is the dialogbox in the dll
I cannot figure out why this error occurs?is this something related to resource files? Do I need to reference somewhere the resource file?
After fix this, how can I create a instance of the dll and call the messagebox?
Is it something like below?
I create a event for button_click on the application.exe;
void CApp::OnBnClickedCreateDLLDlg(){
// TODO: Add your control notification handler code here
CCReateDLLDlg test;
test.domodal();
}

This error means that your application source file does not have include of an h-file where your constants from the DLL project are defined.

Related

Types from COM DLL not available to my VC++ code after '#import "MyDll.dll"'

I'm a COM newbie trying to make a dirt-simple C++ console app to test consuming a COM DLL. In my lone .cpp file, I include the line
#import "AgLeaderFile.dll"
to import the COM DLL of interest. I added the DLL's directory to "Executable Directories" in Project Properties->Configuration Properties->VC++ Directories. I know it is being found, because the red squiggles under the #import directive disappeared when I added this path, and a .tlh file is getting generated in the project's output directory when I build.
Unfortunately, when I refer to types declared in the .tlh file, I get "undeclared identifier" errors (C2065). It seems like the compiler isn't finding the .tlh file.
What is the correct way to make the types from the generated .tlh file available to my .cpp file? I thought the #import statement was supposed to be enough. Do I need to add $(TargetDir) as an additional include directory or something? (That sounds hacky.)
The types I was trying to reference were in a namespace. Adding a using namespace AgLeaderFileLib fixed my problem.

Dialog resources in a static library

I have a problem with dialog and icon resources in my static library.
I have created a MFC static library with Visual Studio 2008.
I am calling Func() in the static library from Win32 application, It tries to launch a MFC dialog in the static library.
When trying to access the resource I am getting afxCurrentResourceHandle is NULL assertion.
I add this line AFX_MANAGE_STATE(AfxGetStaticModuleState()); in the Func() as the first line. But it didn't help.
I need to use only static library. As per requirement, I should not use dll.
Please help me how to launch a dialog in MFC static library from a non MFC application.
The problem here is that a static library doesn't have an 'associated .res file'. If you are trying to migrate a DLL with resources to a static library, then you will need to also 'export' the resource script (its .rc file plus any associated .rc2 files and other referenced resources) to the client program!
So, just as you would have an #include "module.h" line in the .cpp source(s), you will also need an #include "module.rc" in your program's main .rc file (or, at least, in a file that it includes).
Note: Other fixes that folks have tried, like linking explicitly with extra (pre-compiled) .res files won't work! Although the internal structure of a binary .res file is very similar to any other .obj file, the linker will only ever include one!

visual c++, LINK : fatal error LNK1104: cannot open file

I'm new C++, I have a dll file called DiceInvaders.dll, in my project, I need to use this library, I'm using visual c++ 2010, I set the Linker Input as DiceInvaders.lib and DiceInvaders.dll, I also copied this dll file to my porject directory, I always got error in this line of code:
m_lib = LoadLibrary("DiceInvaders.dll");
assert(m_lib);
The error is assertion failure. How should I solve this? Thank you in advance.
First you cannot pass the DLL to the linker like you are, it is not a file type that the linker recognizes and cannot be linked that way. When you create the Diceinvaters.dll file the linker will create an import library with the same filename and the extension .lib. It appears this is already being done. That is the library file you should pass to the linker when building any application that uses it.
Second, the Diceinvaders.dll file must be accessible in the DLL search path. This varies slightly depending on which version of Windows you are using but is generally something like the following
The directory the program was loaded from.
The current working directory.
The System directory.
The Windows directory.
The directories that are listed in the PATH environment variable.
Placing the DLL in your project directory is not going to be enough. Instead you should place it in the same directory as the EXE file(s) that have a dependency on it.

Cant import dll in C++ application

I have a dll called hecom32.dll. I want to use this in my application. I acll the following:
#import "hecom32.dll"
And I get the following error:
enter Error 1 error C1083: Cannot open type library file: 'c:\users\dvargo\documents\visual studio 2010\projects\johnny\johnny\hecom32.dll': Error loading type library/DLL. c:\users\dvargo\documents\visual studio 2010\projects\johnny\johnny\johnny.cpp 6 1 Johnny
Obviously it cant add it. I am not sure however to determine what is wrong with it. Is there some way that I can analyze the file to see why it cant be imported. Is there a different way to use the functions in the dll?
I am using Visual Studio 2010
This will only work properly if hecom32.dll implements a COM server and has the type library embedded as a resource. You can check that with File + Open + File, select the dll. You'll see the resources listed, there should be one labeled "TYPELIB" with a resource ID of 1 if you open the node.
Surely that's missing, the error message says as much. Embedding a type library is a convention, it isn't required. Just keeping it separate as a .tlb file is possible as well. And of course, it might not be a COM server at all. You can see that by running Dumpbin.exe /exports on the dll. A COM server has at least an export named "DllGetClassObject".
If none of this pans out then you'd better contact the owner of the DLL and ask for help on how to use it properly. Which typically requires having a .h file with the declarations of the exported functions and a .lib file so you can link it.

MFC static library and external rc(resource) file icon loading problem

I have a problem with loading icons from external resource files in main application. I'll try to explain how application is set right now. The resources of the main application includes external dialog *.rc and appropriate *.h. And linker includes dialog implementation (CDialog/CFormView) which resides in external static library *.lib.
External *.rc has:
IDI_MY_ICON ICON "my_icon.ico"
External *.h has:
#define IDI_MY_ICON 10000
Dialog implementation in static lib *.cpp has:
HICON MyDialog::GetNeededIcon()
{
return AfxGetApp()->LoadIcon(IDI_MY_ICON);
}
I thought that it should reside in the same folder as external *.rc file is. I also tried to place them in the main app folder, but application still doesn't load them. Could someone explain me where my_icon.ico is searched in?
P.S. - Contents of files are only examples here.
AfxGetApp()->LoadIcon(IDI_MY_ICON); tries to load the icon from the current app (exe).
If you want to load it from another module, you will either have to remember the handle returned from LoadLibrary, or call GetModuleHandle to retrieve it again.
Your .rc file is compiled by rc.exe to embed the icon in your executable. rc.exe uses the include path to find the resources. This is specified by either the INCLUDE environment variable or by using /I option to rc.exe. If "my_icon.ico" doesn't work, try moving the file or change the include path.
Clarification:
rc.exe compiles .rc files into .res, but its the linker that does the actual embedding into the executable.