|
I have developed a dll say MyExtension.dll which is in folder say c:\data\ but it can be really anywhere. ( One step beyond this is that the dll filename can be renamed to anything)
This dll is loaded by another process SomeProcess.exe which is running from say c:\windows. This process and its code is not in my control.
From within the code in my dll can I programatically determine the name of the dll and the path from which the dll is located (i.e I want to find the current executing code resides in c:\data\MyExtension.dll.)
The best I can think of is using toolhelp api to take a snapshot of all modules in the current process. Then search by my module name by iterating over the MODULEENTRY32 data structure. But this means that I have to hardcode atleast the module (dll) name to search. Is there any other way to basically determine the filename of the dll under which the code is executing.
(From a real world perepective I am developing a ISAPI extension dll loaded by IIS worker process. The file name and path is mapped using IIS configuration)
|
|
|
|
|
Use the GetModuleFileName API. The hModule parameter is the hinstDLL passed to your DllMain . You will need to cast it to a HMODULE . i.e. HMODULE hMod = reinterpret_cast<HMODULE>(hinstDLL); .
Steve
|
|
|
|
|
Thanks for letting me know that.
Unfortunately because the dll is a atl server dll it has a different dll main method as defined by the ATL server framework. So the above method won't work.
I am quoting from MSDN.
CAtlDllModuleT::DllMain
The optional entry point into a dynamic-link library (DLL).
BOOL WINAPI DllMain(
DWORD dwReason,
LPVOID /*lpReserved*/
) throw( );
Parameters
dwReason
If set to DLL_PROCESS_ATTACH, the DLL_THREAD_ATTACH and DLL_THREAD_DETACH notification calls are disabled.
lpReserved
Reserved.
Stephen Hewitt wrote: Use the GetModuleFileName API. The hModule parameter is the hinstDLL passed to your DllMain. You will need to cast it to a HMODULE. i.e. HMODULE hMod = reinterpret_cast<hmodule>(hinstDLL);.
Steve
|
|
|
|
|
Use this instead:
HMODULE hMod = reinterpret_cast<HMODULE>(_Module.GetModuleInstance());
Steve
|
|
|
|
|
Thanks very much.
Just one thing it should be _AtlBaseModule.GetModuleInstance()
Cheers
kanad
Stephen Hewitt wrote: HMODULE hMod = reinterpret_cast<hmodule>(_Module.GetModuleInstance());
|
|
|
|
|
Ok. I haven't got the latest ATL (I still use MSVC6, pity me) so I just gleamed this advice from the documentation and knowledge of MSVC6's version of ATL.
Steve
|
|
|
|
|
try this
TCHAR tczFileName[ MAX_PATH ];
MEMORY_BASIC_INFORMATION stMemoryInfo;
static int nAddress;
HMODULE hModule = 0;
// Get the information about the virtual address space of the calling process
if( VirtualQuery( &nAddress, &stMemoryInfo, sizeof( stMemoryInfo ))
!= 0 )
{
hModule = reinterpret_cast<hmodule>(
stMemoryInfo.AllocationBase);
}
// Get the exe's or ddl's file name
DWORD dwFileNameLength = GetModuleFileName( hModule,tczFileName,
MAX_PATH );
nave
|
|
|
|
|
Hi,
I would like to use memcpy() function to copy my source data into my destination data at a time rather than using for loop to go one by one. But the problem that I am not understanding is, my destination buffer size is not same as my source buffer size , but is greater than the later for sure. So, what all I want to implement is first copy all the source data into my destination buffer and again copy the source data into the rest of my destination buffer (yeh, this time the length of the copied buffer shoudl be the size of the left over buffer from the first iteration). For example-
Say my source buffer = 630000 bytes, destination buffer = 630272 bytes
So on fisr iteration of memcopy i would copy the whole 630000bytes of my source buffer into my destination buffer, so at this point destination buffer is left with 272bytes more room, so what I want is to copy the first 272 bytes of source buffer into the remaining destination buffer.
Is there anyway to implement this using memcpy() or memmove() etc functions?? I would really appreciate if anyone can help me out in this.
thanks in advance,
-Pav
|
|
|
|
|
pavanbabut wrote: Say my source buffer = 630000 bytes, destination buffer = 630272 bytes
So on fisr iteration of memcopy i would copy the whole 630000bytes of my source buffer into my destination buffer, so at this point destination buffer is left with 272bytes more room, so what I want is to copy the first 272 bytes of source buffer into the remaining destination buffer.
Is there anyway to implement this using memcpy() or memmove() etc functions?? I would really appreciate if anyone can help me out in this.
I am not sure why you would want to do this... but you can add to a pointer to offset location. if you want byte offset, only add to char pointers.
void strangecopy(char *dest, int destsize, char *source, int sourcesize)
{
do
{
if (destsize<sourcesize)
{
memcpy(dest,source,destsize);
} else
{
memcpy(dest,source,sourcesize);
}
dest+=sourcesize;
destsize-=sourcesize;
} while (destsize>sourcesize);
}
_________________________
Asu no koto o ieba, tenjo de nezumi ga warau.
Talk about things of tomorrow and the mice in the ceiling laugh. (Japanese Proverb)
-- modified at 23:32 Thursday 6th April, 2006
|
|
|
|
|
Hi,
thanks for your reply. yeh, it looks strange.. hehe.. memcpy() is the only way that I can think of to get around the for loop which greatly reduces the speed in real time. Actually my destination buffers are the buffers that are allocated on a PCI board which should be in multiples of 1024 only whereas my source data is not in multiples of 1024. So, the only way I cna do this is as follows-
iteration1- destination buffer1(0:629999) = srouce buffer
iteration2- destination buffer1(630000:630271) = source buffer(0:271)
destination buffer2(0:629727) = source buffer(272:630000)
iteration3- destination buffer2(629728:630272) = source buffer(0:543)
destination buffer3(0:629455) = source buffer(544:630000)
.....
think the destination buffers as circular buffers.
Hope now the problem is clear... Actually I haven't gone through your example, will do now after my dinner
thanks,
-Pav
|
|
|
|
|
Typically the advantage of using one of the supplied functions, like memcpy or memmove is that they are optimized to use the best possible processor instructions. If you code the same operation as a for loop, your performance might be less.
People that start writing code immediately are programmers (or hackers), people that ask questions first are Software Engineers - Graham Shanks
|
|
|
|
|
Hi,
Yeh your are right, that is why I want to incorporate memcpy()/memmove() functions in my code, but as I have explained, I am not sure how to implement them efficiently in my tricky buffer allocations. I am working on this from 2 days now to get it working. It would be great if anyone can come up with generalized solution for my problem .
thanks,
-Pav
|
|
|
|
|
i want to open a zipfile and want to pass a string on it.is it necessary to use serialization?.CFileDialog is used to Browse and Select a file.?
lekshmi
|
|
|
|
|
|
Hi WhiteSky,
Thank u for your reply.But i just want to open a password protected zipfile and Which Will Prompt for a Passwordwhen opened.how can i code it in VC++6.0.
CFileDialog can be used for selecting a file ,but it wont a open the file?.is there any MFC used for that?
Plz Help Me!
thanks in advance
lekshmi
|
|
|
|
|
Hi lekshmipriya ,
Do you need to open dialog in your zipfile for get password ?
|
|
|
|
|
Hi
I am using DLL (dynamic loading) into another DLL.
Say the first one as (Main DLL) and the sendond one as ( SUb DLL ).
My application use the Main DLL directly also its Dynamic loading.
Now when the application closed the destroctor of the (Main DLL) call one funtion of SubDLL. And there the application crash.
The problem is not about the function. As If I am calling any function of the SubDLL from the Destructor of the MainDLL the program crashed.
Can any body please tell me the reason and solution
Regards
Anil
|
|
|
|
|
I do not know enough to answer your question, but I would look at whether the main program thread is still running when you are shutting down the DLL as the functions in the DLL are mapped to the process space and use the stack of the calling thread.
To really know what is happening I recommend that you pick up a copy of "Programming Applications for Microsoft Windows" by Jefferey Richter (absolutly the best source of information).
Good Luck!
INTP
Every thing is relative...
|
|
|
|
|
I suspect the problem is caused by trying to call FreeLibrary from the DllMain of the main DLL - Destructors for global C++ objects in a DLL are called from DllMain . Basically in a DllMain function the system holds the "loader lock" so you can't call any function that requires this lock. That's why you're only meant to do simple initialization in DllMain : Calling LoadLibrary or FreeLibrary from DllMain is definitely out of the question. As mentioned earlier this means that in a DLL you can't call LoadLibrary or FreeLibrary from the constructor or destructor of a class that has a global instance.
Steve
|
|
|
|
|
Thanx for your advice.
Though I solved my problem in other ways, I think I have to explore about DLL little more and with reference to your message I will proceed.
Regards
Anil
|
|
|
|
|
I am writing an application that includes communications over RS232 with a terminal window.
CEditWiew looks great because I need copy and paste etc. but it's wrapping is done on a whole word basiss rather than character at a time.
Is there an option that would provide character at a time wrapping rather than deriving my own class from CScrollView?
Thanks.
Elaine
The tigress is here
|
|
|
|
|
Look at the EM_SETWORKBREAKPROC message and implement your own EditWordBreakProc() function to do the custom word breaks. Just break wherever you like. It might require a bit of trickery to work out where to put the breaks. You can categorise every character as a delimiter and let the edit control work out where to put the breaks - this should do the trick.
<edit>Oops... should be EM_SETWORDBREAKPROC not EM_SETWORDBREAK </edit>
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
-- modified at 0:25 Friday 7th April, 2006
|
|
|
|
|
|
HI
i wanna the code of TOERS OF HANOI with graplical user interface GUL
|
|
|
|
|