|
Hai
In my project i had loaded Resourcesdll in
InitInstance() function. After it get's loaded i
want to load the someother resourcedll based on user
click on button.
My question is how to load different resoucrcedll
at runtime.?
Regards
sakthi
|
|
|
|
|
Look for LoadLibrary() and GetProcAddress() in the MSDN.
|
|
|
|
|
I'm currenty writing an application which indexes a list of 'plug-ins'. Here's the piece of code that creates the index of al valid plug-ins:
void BuildPluginList()
{
CFileFind finder;
PluginList.RemoveAll();
if(!finder.FindFile(".\\Plug-ins\\*.dll"))
AfxMessageBox("Can't find Plug-in directory", MB_ICONHAND, NULL);
unsigned long dllCount = 0, pluginDllCount = 0;
CString filename; HMODULE hmod;
BOOL isMore = TRUE;
while(isMore)
{
isMore = finder.FindNextFile();
dllCount++;
CFile f (finder.GetFilePath(), CFile::modeRead | CFile::typeBinary);
hmod = ::LoadLibraryEx(finder.GetFilePath(), (void*)f.m_hFile, LOAD_WITH_ALTERED_SEARCH_PATH);
if (GetProcAddress(hmod, ("OhDuh"))
{
pluginDllCount++; PluginList.Add(finder.GetFilePath());
}
}
The code won't work. If the 'Plug-ins' directory contains 5 DLLs, whereof 2 real plug-ins (that is, when they have the function 'OhDuh'), dllCount will be 5 (correct), but pluginDllCount will be zero (not correct).
When I paste a GetLastError after the LoadLibraryEx, I get a sharing violation error (32).
Why?
|
|
|
|
|
Sorry for bothering you. I fixed the problem. I just had to add CFile::modeDenyNone to the flags, so that the dll could be loaded without being stopped by object 'f'.
|
|
|
|
|
Hello all,
I make a DLL file using VC and it seems that using VC to create the DLL file, doesn't need to write a .def file.
The strange is i can load the DLL file successfully(use LoadLibrary) but i can get the function the DLL exposes(use GetProcAddress).
The cpp file in this DLL project is shown following:
/***************************************************************/
#include "windows.h"
int ShowIt(void)
{
MessageBox (NULL, TEXT("YAYAYAYA !!"),
TEXT("PART 1"), MB_OK);
return 0;
}
/*******************************************************************/
The .h file looks like:
#define DllExport __declspec(dllexport)
#define DllImport __declspec(dllimport)
extern "C" DllExport int ShowIt(void);
/********************************************************************/
Is there any thing wrong!? Thanks for your help ??
|
|
|
|
|
DllExport int ShowIt(void)
{
MessageBox (NULL, TEXT("YAYAYAYA !!"),
TEXT("PART 1"), MB_OK);
return 0;
}
You do not need extern "C" DllExport int ShowIt(void);
Just write in your .h file
DllExport int ShowIt(void);
|
|
|
|
|
Does anyone know how to load a function from a .dll file?
The Fat Cat
|
|
|
|
|
Read the help in VC++. The functions you want are LoadLibrary and GetProcAddress.
Graham.
|
|
|
|
|
Look for LoadLibrary() and GetProcAddress() in the MSDN.
|
|
|
|
|
Hi, I am 18 yrs old and am just a beginner. I use Microsoft Visual C++. So can anyone paste the required code for changing the text and background color using conio.h in a console application? And how can I create registration entries? Thanx
Asesh shrestha
|
|
|
|
|
Hello,
Use FillConsoleOutputAttribute function to change text and background color
With Regards,
R.Selvam
|
|
|
|
|
Hey guys I am sorry but I am just learning to program on microsoft rather on unix, can someone please tell me, how to write programs that can run on all platforms in Microsoft?? Do I need some kind of Macro or a MAKEFILE or something like that?
|
|
|
|
|
Do you mean that only one source code version is needed to compile different programs, one for each platform? Or do you mean that you want to make one program (or more already comiled files) that run on every platform of Windows?
|
|
|
|
|
Hello Dear Sir.
The point is:
that i want to use .dll that implement from visual c++ to work with my java application but i don't know how to do it.
so i want to know..
1.How can i make vc++ source code into .dll ?
2.How can i make java use that .dll ?
3.Could you introduce me to some books or websites on how to use .dll with Java?
please ,help me. It's about my senior project.
Thanks for your help.
|
|
|
|
|
Hi,
There is a method called System.loadLibrary("dll name");
Check the docs in the System class. Its enough the file name is
mentioned as argument not the extension (.dll).
Create a .dll file using the VC++ environment and put it in the
same directory as your java file.
You need to even use the Javah tool to form the header file from your java file. U need to use header files like jni.h
include the header file formed in the c or c++ file and then
form the .dll
use -jni option in javah command
Look at Java Complete Reference
Java Native Methods( O Reilly ) for the remaining information
Hello everybody this is Kalyan
|
|
|
|
|
Hi to all!
I'm not very familiar to VC++, but I have to call a function from a forgein DLL. With the command: DUMPBIN /EXPORTS Name.dll I tried to find out, which functions the DLL contains, but I only get the following to see:
ordinal hint RVA name
1 0 000011D7 DllCanUnloadNow
2 1 00001209 DllGetClassObject
3 2 00001222 DllRegisterServer
4 3 00001231 DllUnregisterServer
I'm sure that these are not the functions I have to call! So what can I do? Can anyone give me a hint to get access to this DLL!?
Thx!
|
|
|
|
|
You seem to be looking at the internals of an in-process COM object housing DLL. One way to check this is:
1. In a DOS prompt, type regsvr32 yourdllfilename.dll.This should either fail or succeed. If it succeeds, you are looking at a COM object housing.
2. If successful, the easiest way to see whats in the DLL is #import the dll file in C++ (usually in stdafx.h) and then have a look in your debug directory for a .tlh file... that is the type library wrapper header. If you look inside it, you should see all the interfaces and objects exposed, as well as COM SmartPointer definitions...
Good luck
www.kinkycode.com
[Glossary Manager] [AfterThought Backup Lite]
99 little bugs in the code, 99 little bugs,
Fix 1 bug, recompile....
101 little bugs in the code...
|
|
|
|
|
Dll is a com object. to get the names of function open dll in dependency walker shipped with Visual Studio 6.0 by microsoft or u can get it on net.
Hope it helps u. happy coding
Get the facts or facts will get you and when you get them, get them right or they will get you wrong.
Happy Coding
|
|
|
|
|
Hi Dears
I've made a VC++/ATL Com Add-in for MS Outlook.
How to make Installation Program to load ATL Com Add-in(.dll) with MS Outlook ?
Please guide me ..............
I'll be grateful.
Kind Regards
Atif (abqau@hotmail.com - abqau@yahoo.com)
Watch Your Thoughts for they will become your actions.
Watch Your Actions for they will become your habits.
Watch Your Habits for they will become your beliefs.
Watch Your Beliefs for they will determine your destiny.
|
|
|
|
|
/**
* i want to create simple dll file from the following code that i can use this dll in
* other c++ project as well as in java & vb.
* this is the following code.
**/
/////////////////
// mathLib.h //
/////////////////
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class mathLib */
#ifndef _Included_mathLib
#define _Included_mathLib
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: mathLib
* Method: plus
* Signature: (JJ)D
*/
JNIEXPORT jdouble JNICALL Java_mathLib_plus
(JNIEnv *, jobject, jlong, jlong);
/*
* Class: mathLib
* Method: minus
* Signature: (JJ)D
*/
JNIEXPORT jdouble JNICALL Java_mathLib_minus
(JNIEnv *, jobject, jlong, jlong);
/*
* Class: mathLib
* Method: multiply
* Signature: (JJ)D
*/
JNIEXPORT jdouble JNICALL Java_mathLib_multiply
(JNIEnv *, jobject, jlong, jlong);
/*
* Class: mathLib
* Method: divid
* Signature: (JJ)D
*/
JNIEXPORT jdouble JNICALL Java_mathLib_divid
(JNIEnv *, jobject, jlong, jlong);
#ifdef __cplusplus
}
#endif
#endif
//////////////
// math.cpp //
//////////////
#include <jni.h>
#include <stdio.h>
#include <iostream.h>
#include "mathLib.h"
class calculator {
public:
long c;
long plus(const long a, const long b);
long minus(const long a, const long b);
long multiply(const long a, const long b);
long divid(const long a, const long b);
};
long calculator::plus(const long a, const long b) {
c = a + b;
cout<< "+-----------------------------------------+"<<endl;
cout<< "|"<< a << " + " << b << " = " << c << endl;
//cout<< "+-----------------------------------------+"<<endl;
return c;
}
long calculator::minus(const long a, const long b) {
c = a - b;
//cout<< "+-----------------------------------------+"<<endl;
cout<< "|"<< a << " - " << b << " = " << c << endl;
//cout<< "+-----------------------------------------+"<<endl;
return c;
}
long calculator::multiply(const long a, const long b) {
c = a * b;
//cout<< "+-----------------------------------------+"<<endl;
cout<< "|"<< a << " * " << b << " = " << c << endl;
//cout<< "+-----------------------------------------+"<<endl;
return c;
}
long calculator::divid(const long a, const long b) {
c = a / b;
//cout<< "+-----------------------------------------+"<<endl;
cout<< "|"<< a << " / " << b << " = " << c << endl;
cout<< "+-----------------------------------------+"<<endl;
return c;
}
JNIEXPORT double JNICALL Java_mathLib_plus
(JNIEnv *env, jobject obj, jlong a, jlong b) {
calculator cal;
return cal.plus(a, b);
}
JNIEXPORT double JNICALL Java_mathLib_minus
(JNIEnv *env, jobject obj, jlong a, jlong b) {
calculator cal;
return cal.minus(a, b);
}
JNIEXPORT double JNICALL Java_mathLib_multiply
(JNIEnv *env, jobject obj, jlong a, jlong b) {
calculator cal;
return cal.multiply(a, b);
}
JNIEXPORT double JNICALL Java_mathLib_divid
(JNIEnv *env, jobject obj, jlong a, jlong b) {
calculator cal;
return cal.divid(a, b);
}
|
|
|
|
|
There's an easier way to do this.
#include <windows.h>
// This is array of nul-terminated names, intended to be
// passed to GetProcAddresses(). The first name is the
// name of the library to open. The remaining names are
// the names of functions that we wish to obtain pointers
// to. There must be an extra nul byte at the end of this
// array.
//
// We will supply a companion array into which the
// pointers will be stored.
const TCHAR User32Names[] = {"User32.dll\0\
MessageBoxA\0\
MessageBoxExA\0\
\0"};
// Here's our companion array for the pointers. The first
// pointer will actually be the handle to the library.
typedef struct {
HINSTANCE library;
int (WINAPI *lpfMsgBox)(HWND, LPCSTR, LPCSTR, DWORD);
int (WINAPI *lpfMsgBoxEx)(HWND, LPCSTR, LPCSTR, DWORD, WORD);
} USER32PTRS;
USER32PTRS User32Ptrs;
BOOL GetProcAddresses(LPTSTR arrayName, HINSTANCE **arrayPtrs)
{
HINSTANCE handle;
HINSTANCE **temp;
temp = arrayPtrs;
// Load the library
if ((handle = LoadLibrary(arrayName)))
{
*(arrayPtrs)++ = handle;
// Now go through each name and GetProcAddress() it
for (;;)
{
arrayName += lstrlen(arrayName) + 1;
if (!(*arrayName)) break;
if (!(*(arrayPtrs)++ = (HINSTANCE)GetProcAddress(handle, arrayName)))
{
*temp = 0;
FreeLibrary(handle);
return(FALSE);
}
}
return(TRUE);
}
return(FALSE);
}
void main(void)
{
GetProcAddresses((LPTSTR)User32Names, (HINSTANCE **)&User32Ptrs);
if (User32Ptrs.library)
{
User32Ptrs.lpfMsgBox(0, "Test1", "Test1", MB_OK);
User32Ptrs.lpfMsgBoxEx( 0, "Test2", "Test2", MB_OK,
MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
FreeLibrary(User32Ptrs.library);
}
}
|
|
|
|
|
I certainly do think that it's much easier, and I really don't see the basis for your allegation about shared memory locations and crashes. The global variables aren't shared between processes, and certainly a particular DLL would not be simultaneously mapped numerous, different places within one process.
As far as being threadsafe, that would be as simple as either putting a Enter/Exit critical section around the call, or calling the function from DllMain().
|
|
|
|
|
How can I export classes using DLLs. I dont want to use MFCs. Is tere any other way.
|
|
|
|
|
i will just give you the idea,
class myclass
{
public:
void dosomthing(); // and its implementation inthe cpp
};
in .cpp
dllexport myclass* GetMyClass()
{
myclass* theclass;
theclass = new myclass;
return myclass;
}
so you have to load the dll,
get the proc address of GetMyClass
and call it,
you have the pointer to the class in the dll.
The World is getting smaller and so are the people.
|
|
|
|
|
hi friends,
how to invoke vb com dll through c++ dll.
thanks in advance
|
|
|
|
|