I understand that the files using the exported class or function need to call this class or function with dllimport and the file containing the exported class or function needs to call this class or function with dllexport. But I tried to use __declspec(dllexport) only instead of the statements above. It still works. Is there anything I am missing?Why'd we have to switch between dllexport and dllimport? Thanks.
In the project that exports something, you must marked the exported symbols (such as functions or types) with __declspec(dllexport). However, in the project where you import them, you must mark them with __declspec(dllimport). The code above is a little trick to have a single declaration of these symbols. By defining DLLMICRO in your exporting project, you make sure these symbols are compiled with the __declspec(dllexport) markup, while in the importing project where DLLMICRO should not be defined, they would end up marked with __declspec(dllimport).
In my last post, I tried to explain that if I use dllexport only without using a macro to switch between dllexport and dllimport, my app still works. In other words, I don't see why I need dllimport. What problems will I have without dllimport? Thanks.
I tried to explain that if I use dllexport only without using a macro to switch between dllexport and dllimport, my app still works.
You tried. But nobody still understands what "I use", "switch between dllexport and dllimport", "app works" really mean. Without seeing how you "use", "switch" and test "app working" nobody would help you with your question.
I believe, cilu has fully answered your question, and now the question is whether you comprehend the answer.
Generally, the sentence "the program works" doesn't prove anything. In most cases, this means: "program crashes once per month and this crash cannot be reproduced" or "program works on my computer, but crashes on another computer/Windows version".