|
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
|
|
|
|
|
hi friends,
how to invoke vb com dll through c++ dll.
thanks in advance
|
|
|
|
|
While using any 132 col printer in Windows NT Size 15X12 doesnt appears.
What should I do?
|
|
|
|
|
This is a great little timesaver right here. I wanted to say that I appreciated your code very much and it was quite helpful to me.
-Thanks Again
Desert Eagle
|
|
|
|
|
Seriously, using /DelayLoad feature in VC6 makes loading dlls so much easier.
In short, you link with delayimp.lib and somedll.lib and add /DELAYLOAD:"somedll.dll" to linker switches.
Then, you call a function from somedll.dll, say somefunc(). since it's delayloaded, the compiler will generate wrapper code that will call the load libary, getprocaddress, etc. for you. If the DLL is not found, or the function is not found in the DLL, an exception is thrown.
for example, say we want to use a function from iphlpapi.dll, GetNetworkParams.
this is all we need:
__try
{
FIXED_INFO netInfo;
DWORD dwSize = sizeof(FIXED_INFO);
if (GetNetworkParams(&netInfo, &dwSize) == ERROR_SUCCESS)
{
//process return value
}
}
__except (puts("No GetNetworkParams"), 1)
{
}
Pretty easy.
Ryan Schneider
NeoWorx Inc.
|
|
|
|
|
I don't understand why we need to use /DELAYLOAD ? If I use .lib from my .dll I don't need to use LoadLibrary, app framework will do it for me. So, what is this with /DELAYLOAD ?
|
|
|
|
|
You use delayload or LoadLibrary/GetProcAddress when you want your program to still be able to run if the .dll you're importing from does not exist. This way you can use features in newer versions of Windows, for example, and still run without them on older ones.
The LoadLibrary method can also be used when you don't know the name of the library at compile time, say for plugins.
|
|
|
|
|
See I was too lazy to do what you did and just did it the Quake2 way (which is where I first saw it used):
Make a structure full of function pointers and have one function retrieve the pointers. But of course, if you're only grabbing a subset of the functions that are exported, your way is excellent! I'll have to remember this =)
|
|
|
|
|