This is my first time working with DLL's and I am at a bit of a loss.
Not because I don't understand the code. But because all of the tutorials Im following and they are breaking at some points.
First I attempted this, but my work was cut short when the javah
command would not work erroring out with the message: Error: Could not find or load main class com.sun.tools.javah.Main
I then moved on to make my own ddl's so that I can call them from C a library. Found this video and I was able to follow it and its page on the Microsoft page to make the dll. Note that I am fully capable of following the example. The one part that I struggle with is what happens if I don't have the header file or a lib file to the DLL. So then I started following this example and visual studios is saying that import my not exist.
I found that others were able to get the same exact thing working.
What am I doing wrong? End goal, I'd like to know how to create a DLL file like in the video. And only with the DLL file in my possession, access its functions.
So if the DLL was created with the following:
Header
namespace nmspace
{
class myclass{
public:
static __declspec(dllexport) void Crap();
};
}
Source.cpp
#include "Header.h"
using namespace std;
#include <iostream>
namespace nmspace
{
void myclass::Crap(){
cout << "Some Crap";
}
}
How would I call it via LoadLibarary or LoadLibararyA. Note that this did not work for me
To read the dll:
#include <Windows.h>
#include <iostream>
using namespace std;
void PrintFullPath(char * partialPath)
{
char full[_MAX_PATH];
if (_fullpath(full, partialPath, _MAX_PATH) != NULL)
printf("Full path is: %s\n", full);
else
printf("Invalid path\n");
}
int main(){
HMODULE hMod = LoadLibrary("SimpleDLL.dll");
if (NULL == hMod)
{
cout << "LoadLibrary failed\n";
PrintFullPath(".\\");
system("PAUSE");
return 1;
}
}
In the above code, I print out the current working directory. In that directory I have placed my dll. Still the dll is not being loaded.
I am using Visual Studios if that matter. I would also be intrested to see how I would compile the above c++ code via command line and include the dll with it!
EDIT:
I also found this but it relys on the header file as well. Note that I will know what the function names and formats are through the documentation. I just have no header file!