cl.exe and dll questions (dumpbin included)

Hi, so I created a dll using some code:

MyClass.h
1
2
3
4
5
6
7
8
9
#ifndef MYCLASS_H
#define MYCLASS_H

class __declspec(dllexport) MyClass {
public:
	MyClass();
};

#endif 


MyClass.cpp
1
2
3
4
5
6
#include "MyClass.h"
#include <iostream>

MyClass::MyClass() {
	std::cout << "Hello, World\n";
}


cl.exe /EHsc MyClass.cpp /LD

1) Okay, MyClass.dll MyClass.exp and MyClass.lib are created successfully. What exactly is MyClass.exp used for?

-------------------------------------
I then wrote the toy program:

TestUsage.cpp
1
2
3
4
5
6
#include "MyClass.h"

int main(int argc, char* argv[]) {
	MyClass obj;
	return 0;
}


cl.exe /EHsc TestUsage.cpp MyClass.lib

Build successful.
1
2
TestUsage.exe
Hello, World


Next I ran dumpbin /EXPORTS TestUsage.exe and noticed the mangled c++ TestClass symbol. I assumed this was the work of __declspec(dllexport) from my 'MyClass.h' so I changed that to __declspec(dllimport). Recompiled and everything was peachy with dumpbin reporting zero exports.

My second question is, why does TestUsage.exe still import MyClass even though it was dllexport in the class definition?

Any extra information gets you karma points in my book =-)!
Last edited on
A DLL is not necessary to export any symbol unless you want to link to it at runtime using LoadLibrary() and GetProcAddress().
It is enough to link against import library file to access all functions from that DLL.
Where is your DLL? "MyClass.h" is your header, "MyClass.cpp" is your cpp file for that header, and "TestUsage.cpp" is the entry point for your program. You seem to have forgotten to post your DLL code my friend and as such we cannot answer some of your questions :P.

Also the "MyClass.exp" appears to be missing as well, I can't very well tell you what's in the box if you don't show me first.
Last edited on
Re-read my post completely Computergeek01. MyClass is the DLL code. You aren't required to have a DLL entry point. Plus, I even wrote, "1) Okay, MyClass.dll MyClass.exp and MyClass.lib are created successfully."

I also understand this modoran. I was more interested in what most people do with a usable header. Do library developers usually rewrite the header to replace dllexport with dllimport and then redistribute that?
Last edited on
Topic archived. No new replies allowed.