|
Hello.
my problem is that i'm loading a dll to extract some data but it gets lost when i unload the library, i have the following struct
<br />
struct tagPLUGIN{<br />
PCHAR Name;<br />
PCHAR FileName;<br />
UINT Category;<br />
UINT Vital;<br />
ULONG Id;<br />
UINT isUI; <br />
};
and from my main exe i just load the library, get the proccess address and call a dll function to fill the structure
<br />
extern "C" __declspec(dllexport) void GetPlugInfo (tagPLUGIN *plugin)<br />
{<br />
<br />
AFX_MANAGE_STATE(AfxGetStaticModuleState());<br />
plugin->Category=TOOL;<br />
plugin->Id=0;<br />
plugin->isUI=TRUE;<br />
plugin->Name=new char[25];<br />
strcpy(plugin->Name,"Configuración de Sistema\0");<br />
plugin->Vital=FALSE;<br />
}<br />
loading the dll
<br />
tagPLUGIN plugin;<br />
typedef void (*GetPlugInfo)(tagPLUGIN *info);<br />
HMODULE dll=LoadLibrary(tmp_string);<br />
GetPlugInfo getPlugInfo = (GetPlugInfo)GetProcAddress(dll,"GetPlugInfo");<br />
(getPlugInfo)(&plugin);<br />
plugin.Id=ID++;<br />
plugin.FileName=new char[tmp_string.GetLength()+1];<br />
strcpy(plugin.FileName,tmp_string.GetBuffer());<br />
FreeLibrary(dll);<br />
but right after FreeLibrary(dll) my two PCHAR values are corrupt, i know the problem is in the new char[size] , so how can i pass a PCHAR to a dll function and allocate and assign a string without loosing it after freelibrary?
|
|
|
|
|
you could do the allocation in the calling module, not in the DLL. or, just use a fixed-size buffer for the text in the structure.
or, use global memory (ie. GlobalAlloc, etc) to allocate the strings.
Image Toolkits | Image Processing | Cleek
|
|
|
|
|
Hi Chris,
no it doesn't, i was trying to with HeapAlloc, but both after i call FreeLibrary(dll)
i get a <bad ptr=""> value.
By the way, why it works in debug mode?
anybody can give me links of dll tutorials/guides please.
Best Regards
|
|
|
|
|
Your dll, and or exe, is likely being staticly linked to the CRT.
That is, the dll new, malloc, alloc, calloc functions are using a heap local to the dll.
When the dll is unloaded the heap is destroyed.
The debug version is likely set to dynamicly link to the CRT so the exe and dll use the same heap for memory allocations.
...cmk
Save the whales - collect the whole set
|
|
|
|
|
Tthanks for your help.
No, i'm using both debug and release in shared dll, the dll and exe both debug uses debug and release uses release, i've tried, new,malloc,GlobalAlloc and Heap Alloc, same result.
i'll do some more reading about dlls and retry this, but for now i have an idea, can you tell me if this could be the good way:
near that code i have some code to read from the registry and i've noted that when in RegQueryValueEx you pass a buffer too small for the required data (REG_SZ) it returns the size of the buffer needed so you can reallocate the memory for the buffer with that size, so i'll code my GetPlugInfo in that way and i'll pass the PCHAR vars with the memory preallocated. Is that a good solution?
Thanks in advance.
|
|
|
|
|
I'm not sure that you understood what i was talking about.
In VC++
Goto Projects - Settings.
Goto C/C++ - Code Generation.
For both your exe and dll the 'Use run-time library' should be:
'Debug Multithreaded DLL' for your debug builds.
and
'Multithreaded DLL' for your release builds.
There is no reason you can't do what you originally specified.
...cmk
Save the whales - collect the whole set
|
|
|
|
|
Hi,
I want to use arrow key to move focus among dialog controls. But standard dialog does not support this. How can i do it? is there a sample code?
best regards,
|
|
|
|
|
li0000 wrote:
I want to use arrow key to move focus among dialog controls. But standard dialog does not support this.
Yes it does, you just have to set the WS_GROUP styles right. Identify what group of controls (checkboxes, buttons, radio buttons, etc.) you want to move through. Make sure they're in the right tab order. Set the WS_GROUP style on the first control in the group, and unset the style on the remaining controls.
--Mike--
LINKS~! Ericahist updated! | 1ClickPicGrabber | CP SearchBar v2.0.2 | C++ Forum FAQ
Strange things are afoot at the U+004B U+20DD
|
|
|
|
|
Hi Mike
How about CEdit and CComBoBox control? Can I also use this method to implement navigating using arrow keys?
Thanks
|
|
|
|
|
Window Styles
WS_GROUP Specifies the first control of a group of controls in which the user can move from one control to the next with the arrow keys. All controls defined with the WS_GROUP style FALSE after the first control belong to the same group. The next control with the WS_GROUP style starts the next group (that is, one group ends where the next begins).
|
|
|
|
|
Dear gurus,
I am required to write a C++ library program using Visual C++ 6.0.
The criterias are:
1)Create 2 output .dat files one for the library book database and the other for borrowers list and books that are leased.
The first file will list:
Book Title Date added Author Publisher Avilbility status
The second file will list:
Name of borrower Book borrowed Date borrowed Expiry Date
2)The menu of the program should have:
a)Review books database and availability
b)Review/List borrowers/books borrowed
c)Add/alter books list
d)Add/Remove borrowers from the list
Need help ASAP.Only had 2 months experience with C++.Currently I only know how to create classes,make switch statements,arrays,structures and loops.Still not very familiar with I/O writing/reading.I am having headache on how to relate all of them.Another question is how do I individually remove the data from the database one by one specifically?I know how to write a list and add but let's say member #3 already returns his book how to remove him from the list and change the book availability status in the other file to available again?
Thanks in advanced.
|
|
|
|
|
As most of us here only help with understanding and small tidbits of code, you probably won't find your completed project, but here is a couple of pointers (no pun intended ):
Adding items is easy: just append each item at the end of the list, then save just the appended data to the file. However, when you remove the items, depending on where it is in the file, you will have to remove the item and shift everything after it back 1 spot. Since you don't have a lot of programming experience, I suggest this: load the list into memory and do all the processing there. Each add will add to the list to memory, and append the item to the file. Each remove, however, will remove the item from memory and rewrite the file from scratch.
I know this process is can be slow when there are a lot of items, but its a surefire way to make it work. The other alternative is figure out some way to use ODBC or some other SQL server, which have much more efficient ways of inserting and removing items from databases.
Hope this helps you out a little. Happy coding!
|
|
|
|
|
Hello,
I have an application that uses CSocket and I am trying to put
the socket I/O into a thread.
I tried to put it into a non-derived-class worker thread, but
this clearly doesn't work, in that the program crashes.
I tried to create a derivative of CWinThread but that compiled
but didn't link, because it cannot find the runtime class info.
Can someone point me to an example of a program that puts
socket I/O in a thread successfully?
Thanks.
|
|
|
|
|
|
That article deals with passing a socket to a thread.
What I'm trying to do is create the socket inside the thread.
I can detect that the thread is being run, but the moment
I call Create, it crashes the program.
I get the following stack :
CMapPtrToPtr::GetValueAt(void * 0x00000744) line 179 + 3 bytes
CAsyncSocket::LookupHandle(unsigned int 0x00000744, int 0x00000000) line 385 + 15 bytes
CAsyncSocket::AttachHandle(unsigned int 0x00000744, CAsyncSocket * 0x00de7cf0 {CSocket}, int 0x00000000) line 407 + 13 bytes
CAsyncSocket::Socket(int 0x00000001, long 0x0000003f, int 0x00000000, int 0x00000002) line 557
CAsyncSocket::Create(unsigned int 0x00000000, int 0x00000001, long 0x0000003f, const char * 0x00000000) line 105 + 20 bytes
CSocket::Create(unsigned int 0x00000000, int 0x00000001, const char * 0x00000000) line 45 + 29 bytes
CMyThread::MyMessageHandler(unsigned int 0x00000401, long 0x00aa1180) line 570 + 17 bytes
CWinThread::DispatchThreadMessageEx(tagMSG * 0x00aa10c4 {msg=0x00000401 wp=0x00000401 lp=0x00aa1180}) line 652
CWinThread::PreTranslateMessage(tagMSG * 0x00aa10c4 {msg=0x00000401 wp=0x00000401 lp=0x00aa1180}) line 660 + 20 bytes
CWinThread::PumpMessage() line 841 + 30 bytes
CWinThread::Run() line 480 + 11 bytes
_AfxThreadEntry(void * 0x0011deec) line 125 + 11 bytes
_threadstartex(void * 0x00aa2f80) line 212 + 13 bytes
KERNEL32! 7
|
|
|
|
|
i need to create a payment form on web-page for users, i only know c++ and php.
which one is better between COM or PHP on web-page for credit card trnsaction?
any suggestion for security issues?
thanks
includeh10
|
|
|
|
|
|
Hi Dears,
I can find result of this code ,
unsigned int nPort = 0x7e00;
volatile unsigned char *exAddress;
exAddress =(volatile unsigned char *) nPort;
what is value for exAddress ?
Best regards.
|
|
|
|
|
|
somethings wrong!
exAdress is unsigned char! even though return 0x7e00???
|
|
|
|
|
|
Anyone has any clue what could be causing this ?
Message from VC++ 6.0 linker
error LNK2001: unresolved external symbol __imp__AlphaBlend@44
I'm starting to think this project is jinxed. First my little property headache and now this one.
Thanks for any input.
Best regards,
----------------
Lord Phoenix
----------------
|
|
|
|
|
|
Thanks, that did it.
Funny thing is I have a another project that uses this and I don't ever remember having to do this. Oh well, maybe I just forgot about it.
Again, thanks for your help.
----------------
Lord Phoenix
----------------
|
|
|
|
|