|
a1prashant@yahoo.com wrote: JNIEXPORT void JNICALL Java_gui_config_setManufacturer(JNIEnv *env, jobject obj);
Please let me know how this routine can be called from MFC application.
Did you try calling it?
Nibu thomas
Software Developer
|
|
|
|
|
Thank you for replying.
Issue1: (Is passing NULL, NULL correct??)
typedef void * (__stdcall *DLLPROC)(VOID *, VOID *);<br />
...<br />
DLLPROC pfnProc = (DLLPROC)GetProcAddress(hInst, "Java_gui_Win_getCurrFirmware");<br />
if( pfnProc )<br />
{<br />
AfxMessageBox("Got Java_gui_Win_getCurrFirmware");<br />
VOID * jstr = (pfnProc)(NULL, NULL);
AfxMessageBox("Called!");<br />
}
While calling the procedure, it is expected to send (JNIEnv *env AND jobject *obj)
But currently I am passing NULL, NULL.
Is this correct?
The code runs w/o problem and I able to see the message box "Called".
Issue2: (How do I get c_str from "jstring")The DLL procedure is supposed to return "jstring"
But I need c_str out of it. How do I do the conversion?
I want conversions for atleast
jboolean -> boolean
jstring -> char *
jint -> int
Please help.
-- modified at 1:29 Friday 24th March, 2006
|
|
|
|
|
a1prashant@yahoo.com wrote: While calling the procedure, it is expected to send (JNIEnv *env AND jobject *obj)
JNIEnv and jobject are structures or classes that are declared in "java.h" or "jni.h" . Maybe copying them and passing the values as required should help.
Note: I am a bit tentative about this. I remember there is a file called java.h which contains declarations. Please check the file names. Maybe doing a string search inside java directory should help you. Strings like jobject , JNIEnv . This will take you to the exact file where they are declared.
a1prashant@yahoo.com wrote: But currently I am passing NULL, NULL.
Why?
a1prashant@yahoo.com wrote: Is this correct?
This is wrong. They are expecting something but you are giving nothing!
a1prashant@yahoo.com wrote: (How do I get c_str from "jstring")The DLL procedure is supposed to return "jstring"
Take a look at what jstring is. What kind of datatype is it. Normally these are typedefs or structs . So it must be easy for you once you find them to use them and pass them to funtions.
a1prashant@yahoo.com wrote: I want conversions for atleast
jboolean -> boolean
jstring -> char *
jint -> int
Again I repeat what I said. These are either typedefs or structs . You can copy their declarations.
Nibu thomas
Software Developer
|
|
|
|
|
Thanks a lot for the help.
|
|
|
|
|
Well did it work?
Nibu thomas
Software Developer
|
|
|
|
|
Take a look at these links too...
Java.h[^]
Jni.h[^]
Nibu thomas
Software Developer
|
|
|
|
|
I included the jni.h and jni_md.h files.
However I wonder if following is okay?
The JVM passes JNIEnv and jobjects to the DLL.
Don't know how JVM treats these two parameters before passing.
hInst = ::LoadLibrary("D:\\win_dll.dll");<br />
if( hInst )<br />
{<br />
AfxMessageBox("Loaded win_dll.dll");<br />
typedef void * (__stdcall *fpProc)(JNIEnv *env , jobject obj);<br />
fpProc pfnProc = (fpProc)GetProcAddress hInst, "Java_gui_Win_getCurrFirmware");<br />
if( fpProc )<br />
{<br />
AfxMessageBox("Got Java_gui_Win_getCurrFirmware");<br />
<br />
JNIEnv env;<br />
jobject obj;<br />
VOID * jstr = (fpProc)(&env, obj);
<br />
<br />
AfxMessageBox("Called!");
Thanks!
|
|
|
|
|
a1prashant@yahoo.com wrote: JNIEnv env;
jobject obj;
VOID * jstr = (fpProc)(&env, obj); // Passing w/o initializing
Have you looked at the members of JNIEnv and jobject .
I guess jobject is an empty class.
JNIEnv is a huge class.
What happens when you pass an empty object of JNIEnv to the function. I guess the function will fill it out for you.
Nibu thomas
Software Developer
|
|
|
|
|
It works w/o problem. Actually I'm trying on a sample code, and yet the DLL is not fully loaded.
I'll have to check it after all the things are in place.
Great help Nibu!
Thanks!
|
|
|
|
|
a1prashant@yahoo.com wrote: I'll have to check it after all the things are in place.
Are you checking the output that you get from the function? Well I would like to know!
Nibu thomas
Software Developer
|
|
|
|
|
Hello Nibu,
Sorry for the delayed reply. 2 Day's holiday
I'll soon check it on one of my test machines. And I'll surely let you know the result.
Regards,
Pacific
|
|
|
|
|
I was also having two days holiday.
If it works please tell me. Will be waiting for your response.
Nibu thomas
Software Developer
|
|
|
|
|
When changed an ActiveX object's property by using its property page, clicking on the "Apply" button should reflect the changes to ActiveX object. However, this does not work with my own ActiveX control and clicking on the "Apply" button simply does nothing.
If you know where to put in event handling code for clicking on this "Apply" button, please let me know. Thank you in advance.
|
|
|
|
|
What I'm trying to do is search a binary file for a specified string then copy all of the data in between strings into other files. What commands should I look at that could help me do this? Thanks.
|
|
|
|
|
The easiest way would be the load the whole file into memory, do the search, and then copy the bit you want into the new file (unless the file is so big and that this isn't feasable).
------------------
// Copy.cpp : Defines the entry point for the application.
//
#include "stdafx.h"
#include <tchar.h>
#include <algorithm>
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
// Open the file.
HANDLE hFile = CreateFile(
_T("C:\\a.txt"), // lpFileName,
FILE_READ_DATA, // dwDesiredAccess
FILE_SHARE_READ, // dwShareMode,
NULL, // lpSecurityAttributes
OPEN_EXISTING, // dwCreationDisposition
FILE_ATTRIBUTE_NORMAL, // dwFlagsAndAttributes
NULL // hTemplateFile
);
if ( hFile==INVALID_HANDLE_VALUE )
{
return 1;
}
DWORD dwFileSize = GetFileSize(hFile, NULL);
// Create the file mapping.
HANDLE hMapping = CreateFileMapping(
hFile, // hFile
NULL, // lpAttributes
PAGE_READONLY, // flProtect
0, // dwMaximumSizeHigh
0, // dwMaximumSizeLow
NULL // lpName
);
if ( hMapping==NULL )
{
// Close the file.
CloseHandle(hFile);
return 1;
}
LPVOID pData = MapViewOfFile(
hMapping, // hFileMappingObject
FILE_MAP_READ, // dwDesiredAccess
0, // dwFileOffsetHigh
0, // dwFileOffsetLow
0 // dwNumberOfBytesToMap
);
if ( pData==NULL )
{
// Close the file mapping.
CloseHandle(hMapping);
// Close the file.
CloseHandle(hFile);
return 1;
}
// Now search for the data we want...
// The file data we've loaded.
const char *pStart = reinterpret_cast<const char *>(pData);
const char *pEnd = pStart + dwFileSize;
// The data we're looking for.
const char DataToFind[] = "|Hello|";
const char *pSearchStart = DataToFind;
const char *pSearchEnd = pSearchStart+sizeof(DataToFind)-1; // -1 to strip off the NULL terminator.
// Search.
const char *pMatch = std::search(pStart, pEnd, pSearchStart, pSearchEnd);
if ( pMatch!=pEnd )
{
pMatch += sizeof(DataToFind)-1;
const char *pMatch2 = std::search(pMatch, pEnd, pSearchStart, pSearchEnd);
if ( pMatch2!=pEnd )
{
// Copy out [pMatch, pMatch2).
// Create the output file.
HANDLE hOut = CreateFile(
_T("C:\\out.txt"), // lpFileName,
GENERIC_WRITE, // dwDesiredAccess
0, // dwShareMode,
NULL, // lpSecurityAttributes
CREATE_ALWAYS, // dwCreationDisposition
FILE_ATTRIBUTE_NORMAL, // dwFlagsAndAttributes
NULL // hTemplateFile
);
if ( hOut!=INVALID_HANDLE_VALUE )
{
DWORD dwWritten;
WriteFile(hOut, pMatch, pMatch2-pMatch, &dwWritten, 0);
CloseHandle(hOut);
}
}
}
// Unmap the file.
UnmapViewOfFile(pData);
// Close the file mapping.
CloseHandle(hMapping);
// Close the file.
CloseHandle(hFile);
return 0;
}
Steve
|
|
|
|
|
Steve, if you place code inside of <pre> tags you don't have to fiddle around entering tons of s in a failed effort to line things up.
You may be right
I may be crazy
-- Billy Joel --
Within you lies the power for good - Use it!
|
|
|
|
|
I ticked ignore HTML tags for this one.
|
|
|
|
|
Thanks! This helps me out a lot. I've got a question about the code, though. How do I get it to repeat until the end of the file and how do I make it take the string I was searching for as well?
Example:
|Hello|abcdef|Hello|ghijkl|Hello|mnopqr|Hello|stuvwx|Hello|yz
Then it would output |Hello|abcdef to file1.txt, |Hello|ghijkl to file2.txt, etc.
Sorry if this is asking too much, I'm pretty new to VC++ (I normally code mixed C/++) and handling files. Thanks again for the help.
|
|
|
|
|
There are many ways to do this. This is pretty efficient except when the files get very large.
-------------------------------------
// Copy.cpp : Defines the entry point for the application.
//
#include "stdafx.h"
#include <tchar.h>
#include <algorithm>
#include <shlwapi.h>
#pragma comment(lib, "shlwapi.lib")
#include <string>
#include <sstream>
#ifdef _UNICODE
typedef std::wstring tstring;
typedef std::wostringstream tostringstream;
#else
typedef std::string tstring;
typedef std::ostringstream tostringstream;
#endif // _UNICODE
void WriteData(LPCTSTR pFile, unsigned int n, const char *pBegin, const char *pEnd)
{
// Generate numbered filename.
LPCTSTR pExt = PathFindExtension(pFile);
tstring FileName(pFile, pExt);
tostringstream ss(FileName);
ss.seekp(0, std::ios::end);
ss << n;
ss << pExt;
FileName = ss.str();
// Create the output file.
HANDLE hOut = CreateFile(
FileName.c_str(), // lpFileName,
GENERIC_WRITE, // dwDesiredAccess
0, // dwShareMode,
NULL, // lpSecurityAttributes
CREATE_ALWAYS, // dwCreationDisposition
FILE_ATTRIBUTE_NORMAL, // dwFlagsAndAttributes
NULL // hTemplateFile
);
if ( hOut!=INVALID_HANDLE_VALUE )
{
DWORD dwWritten;
WriteFile(hOut, pBegin, pEnd-pBegin, &dwWritten, 0);
CloseHandle(hOut);
}
}
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
// Open the file.
HANDLE hFile = CreateFile(
_T("C:\\a.txt"), // lpFileName,
FILE_READ_DATA, // dwDesiredAccess
FILE_SHARE_READ, // dwShareMode,
NULL, // lpSecurityAttributes
OPEN_EXISTING, // dwCreationDisposition
FILE_ATTRIBUTE_NORMAL, // dwFlagsAndAttributes
NULL // hTemplateFile
);
if ( hFile==INVALID_HANDLE_VALUE )
{
return 1;
}
DWORD dwFileSize = GetFileSize(hFile, NULL);
// Create the file mapping.
HANDLE hMapping = CreateFileMapping(
hFile, // hFile
NULL, // lpAttributes
PAGE_READONLY, // flProtect
0, // dwMaximumSizeHigh
0, // dwMaximumSizeLow
NULL // lpName
);
if ( hMapping==NULL )
{
// Close the file.
CloseHandle(hFile);
return 1;
}
LPVOID pData = MapViewOfFile(
hMapping, // hFileMappingObject
FILE_MAP_READ, // dwDesiredAccess
0, // dwFileOffsetHigh
0, // dwFileOffsetLow
0 // dwNumberOfBytesToMap
);
if ( pData==NULL )
{
// Close the file mapping.
CloseHandle(hMapping);
// Close the file.
CloseHandle(hFile);
return 1;
}
// Now search for the data we want...
// The file data we've loaded.
const char *pStart = reinterpret_cast<const char *>(pData);
const char *pEnd = pStart + dwFileSize;
// The data we're looking for.
const char DataToFind[] = "|Hello|";
const char *pSearchStart = DataToFind;
const char *pSearchEnd = pSearchStart+sizeof(DataToFind)-1; // -1 to strip off the NULL terminator.
// Search.
unsigned int num = 1;
const char *pMatch = std::search(pStart, pEnd, pSearchStart, pSearchEnd);
if ( pMatch!=pEnd )
{
const char *pMatch2;
do
{
pMatch2 = std::search(pMatch+sizeof(DataToFind)-1, pEnd, pSearchStart, pSearchEnd);
WriteData(_T("C:\\out.txt"), num++, pMatch, pMatch2);
pMatch = pMatch2;
}
while (pMatch2!=pEnd);
}
// Unmap the file.
UnmapViewOfFile(pData);
// Close the file mapping.
CloseHandle(hMapping);
// Close the file.
CloseHandle(hFile);
return 0;
}
Steve
-- modified at 5:12 Friday 24th March, 2006
|
|
|
|
|
Thanks! This helps me out a lot.
|
|
|
|
|
Sir
Can anyone help me in knowing better about
AFX_GETMODULE_STATE macro and why is needed.
Always Be What you Are.
|
|
|
|
|
AfxGetModuleState returns a pointer to thread-local storage for a struct called AFX_MODULE_STATE that stores information about the current running module, including a pointer to the application object.
Vision is Always important and so is your ATTITUDE.
Wishes.
Anshuman Dandekar
|
|
|
|
|
Hi, I have this error message when compling the project:
Creating library ..\giscbir\Debug/geocbir.lib and object ..\giscbir\Debug/geocbir.exp
geocbir.obj : error LNK2001: unresolved external symbol "unsigned long __cdecl CBIRTextTamura(struct tagCBIRIMAGE *,struct tagCBIRTEXTUREDATA *,unsigned long,unsigned long)" (?CBIRTextTamura@@YAKPAUtagCBIRIMAGE@@PAUtagCBIRTEXTUREDATA@@KK@Z)
..\giscbir\Debug/geocbir.dll : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
Anyone got an idea what is the reason? Thanks in advance!
|
|
|
|
|
The reason is that a declaration of the function "unsigned long __cdecl CBIRTextTamura " is present but there is no definition. ie.
unsigned long __cdecl CBIRTextTamura(struct tagCBIRIMAGE *,struct tagCBIRTEXTUREDATA *,unsigned long,unsigned long);
unsigned long __cdecl CBIRTextTamura(struct tagCBIRIMAGE *,struct tagCBIRTEXTUREDATA *,unsigned long,unsigned long)
{
return 0;
}
The most likely cause is that you forgot to add the .CPP file that contains the defintion to your project.
Steve
|
|
|
|
|
It has definition in the header file and implemention in cpp file.
|
|
|
|
|