Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Problem loading a dll in visual c++ 2010?

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
Freiza
Grandmaster Cheater
Reputation: 22

Joined: 28 Jun 2010
Posts: 662

PostPosted: Sat Mar 17, 2012 3:48 pm    Post subject: Problem loading a dll in visual c++ 2010? Reply with quote

I have created two project under same solution.
1) dllfirst contains one.h and sayhello.cpp
2) testdlls contains testing.cpp

one.h
Code:
#define dllmy __declspec(dllexport)
dllmy void hello();


sayhello.cpp
Code:
#include"one.h"
#include<stdio.h>
void hello()
{   printf("hello world to freiza gen");
   }


testing.cpp
Code:
#include<windows.h>
#include<iostream>
#include<conio.h>
using namespace std;

typedef void (*pointers)();
pointers points;

int main()
{
   HINSTANCE libs = LoadLibraryA("dllfirst.dll");
   if(libs==NULL)
   {

      cout<<"File not loaded";
      return 0;
   }
   points = (pointers)GetProcAddress(libs,"hello");
   if(points==NULL)
   {
cout<<GetLastError();            // error code 127
      cout<<"error points is NULL";
      return 0;
   }

   points();
   FreeLibrary(libs);

   _getch();
   return 0;
}


I also made testdlls my startup project and set its common properties->reference to dllfirst. It compiles with no error. But when I run it, it gives me "error points is NULL" this error.
What am I doing wrong?
I could have done it using another way. But I wanted to learn how to use loadlibrary and GetProcAddress to use dll.

_________________
Back to top
View user's profile Send private message Send e-mail
Dark Byte
Site Admin
Reputation: 473

Joined: 09 May 2003
Posts: 25899
Location: The netherlands

PostPosted: Sat Mar 17, 2012 4:03 pm    Post subject: Reply with quote

Your exports are probably wrangled.

Compile your dll as a c program, not as c++

or add a .def file that sets the exportnames properly

_________________
Do not ask me about online cheats. I don't know any and wont help finding them.

Like my help? Join me on Patreon so i can keep helping
Back to top
View user's profile Send private message MSN Messenger
Freiza
Grandmaster Cheater
Reputation: 22

Joined: 28 Jun 2010
Posts: 662

PostPosted: Sat Mar 17, 2012 4:11 pm    Post subject: Reply with quote

Yes converting sayhello.cpp to sayhello.c solved the problem.
But What if I want to do the same for sayhello.cpp ?


@add a .def file that sets the exportnames properly
I didn't understand this statement.

Thank You very much

Edit: I got a solution.
#define dllmy extern "C" __declspec(dllexport).
This solves my problem.

But I still want to know how to add .def file. Please tell.

_________________
Back to top
View user's profile Send private message Send e-mail
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8585
Location: 127.0.0.1

PostPosted: Sun Mar 18, 2012 4:08 am    Post subject: Reply with quote

Inside your solution, add a new file. Choose 'Module Definition File' from the list (.def) of the file types to pick from.

Inside the file you would place:

Code:

LIBRARY YourDllNameHere
EXPORTS
    hello


Some links if you want more info on .def files:
http://msdn.microsoft.com/en-us/library/28d6s79h%28v=vs.100%29.aspx
http://msdn.microsoft.com/en-us/library/d91k01sh.aspx

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites