|
Hi Mark
thank you for your help. It was very useful
|
|
|
|
|
I have a DLL which is being developed in VC6.
This DLL uses internal resources such as a look-up table which i access using
AfxGetInstanceHandle() , FindResource and LoadResource API's
This works as expected.
However I have a project configuration that also creates a static library for the same , in which case the above mentioned API's will not be able to access the internal resource.AfxGetInstanceHandle will provide the handle to the application that uses this static library. With this condition , it seems that the internal resource needs to move to the application that uses the static library. For security reasons I dont want to expose this resource to external applications . Is it possible by some means to access the resource from the static library without having to move the internal resource to the application ?
Any ideas or suggestions are desperately needed .
Thanks
|
|
|
|
|
act_x wrote: Is it possible by some means to access the resource from the static library without having to move the internal resource to the application ?
Try this at the beginning of the function that accesses the resource:
AFX_MANAGE_STATE(AfxGetStaticModuleState());
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
New to VC++, working with 6.0
Trying to read a text file one character at a time. If program finds a comma in text file, it stops and creates a string out of all the preceding characters. No problem reading the file or recognizing the comma. The program won't concatenate the chars into one string.
Here's the code:
char buffer[1];
char cur_char = NULL;
CString cur_data;
UINT bytesread;
do
{
cur_data += cur_char;
bytesread=radardata.Read(buffer,1);
cur_char=buffer[0];
}
while (cur_char != ',');
Every time I run it, cur_data ends up NULL. Here's what else I've tried with the same result:
cur_data = cur_data + CString(cur_char);
cur_data = CString(cur_data) + CString(cur_char)
Thanks in advance!
|
|
|
|
|
cur_data should end-up with NULL as you are adding NULL to it from the beginning.
The following will work;
char buffer[1];
char cur_char;
CString cur_data;
UINT bytesread = 0;
do
{
bytesread += radardata.Read(buffer,1);
cur_char=buffer[0];
cur_data += cur_char;
}
while (cur_char != ',');
--
=====
Arman
|
|
|
|
|
|
pkoelsch wrote: Trying to read a text file one character at a time.
You do realize how inefficient this is, don't you?
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Like I said, I'm new to VC++. No classes, just opened a book. The last time I did any formal computer programming, we still used line numbers. I'm open to any recommendations.
|
|
|
|
|
Hi All,
I always appreciate your help.
I have a problem with ifstream
This is my 'input.txt' file.
The first digit of each line is the length.
How can I read in this file using while() or for()
2 3 4
5 7 8 10 11 12
7 8 10 16 17 54 37 38
3 33 51 48
...
I tried this one.
...
ifstream inpf_EX("input.txt");
for (i=1; i<=N_Of_LINE;i++)
{
inpf_EX>>EXIST[i][0]);
len=EXIST[i][0];
for(j=1; j<=len; j++)
{
inpf_EX>>EXIST[i][j]);
}
}
Thanks!
...
Yonggoo
|
|
|
|
|
Yonggoo wrote: How can I read in this file using while() or for()
Neither are necessary, and their use would only serve to confuse you further. You can use an iterator on a stringstream object, and then use the copy() function. You don't need an extra digit in the front to tell how many items follow. If it has to stay, however, just read it in and ignore it.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
I have not used an iterator on a stringstream.
Does std c++ have iterator?
Thanks!
Yonggoo
|
|
|
|
|
Yonggoo wrote: Does std c++ have iterator?
Yes.
class LineItem
{
public:
LineItem() {}
~LineItem() {}
void setLength(const int length) { _Length = length; }
int getLength() const { return _Length; }
void setNumbers(const std::vector<int>& numbers) { _Numbers.assign(numbers.begin(), numbers.end()); }
std::vector<int> getNumbers() const { return _Numbers; }
private:
int _Length;
std::vector<int> _Numbers;
};
std::ostream& operator<<(std::ostream& os, const LineItem& s)
{
os << s.getLength() << "|";
const std::vector<int> numbers = s.getNumbers();
std::copy(numbers.begin(), numbers.end(), std::ostream_iterator<int>(os, " "));
os << std::endl;
return os;
}
std::istream& operator>>(std::istream& is, LineItem& s)
{
int length;
is >> length;
std::string sNumbers = "";
std::getline(is, sNumbers);
std::stringstream ss(sNumbers);
std::vector<int> numbers;
std::copy(std::istream_iterator<int>(ss), std::istream_iterator<<int>(), std::back_inserter(numbers));
s.setLength(length);
s.setNumbers(numbers);
return is;
}
void main( void )
{
std::ifstream fin;
std::vector<LineItem> lines;
fin.open("c:\\input.txt");
std::copy(std::istream_iterator<LineItem>(fin), std::istream_iterator<LineItem>(), std::back_inserter(lines));
fin.close();
std::copy(lines.begin(), lines.end(), std::ostream_iterator<LineItem>(std::cout, "\n"));
}
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
The following is my code for when I click on a button that's labeled "Start". I use a functor to call my class member function pointer (via Execute(), where Execute() takes an int& parameter). When I set a breakpoint at the Execute() calls, and I hover my mouse over "i", the MSVC debugger tells me that i has some really high value like 4632955, and when I check &i in the immediate window, it tells me the memory address of i. Then, I go into Execute() to call the specific function pointer &MainWindow::DoWork, when I check the input parameter (which takes an int& as mentioned earlier), the memory address of that input parameter is &i + 4 bytes. Basically, what I'm saying is that MSVC shows me different memory address values from the calling function ButtonStart() and within the called function DoWork(). The value from ButtonStart() is wrong, as my int is not some really high number, but the value that is actually received in DoWork() is right, and ends up being 5 (what I set it to in the beginning). This is the first problem and I don't know why this is happening.
The second problem is that some of my lines of execution are being skipped. Actually, that is inaccurate, as they are being executed but I cannot set a breakpoint at some of the lines such as the line int i = 5. MSVC will just shift my breakpoint down to the Execute() calls. My debugging info is turned on, and I'm am building in Debug mode, so this shouldn't happen (I've had it happen when building in Release mode).
void MainWindow::ButtonStart()
{
if (!m_threadPool && !m_source && !m_receiver)
{
m_source = new EventSource();
m_receiver = new EventReceiver();
m_threadPool = new ThreadPool(m_source, m_receiver);
m_receiver->HookThreadPool(m_source);
int i = 5;
CallbackWrapperSpecific<MainWindow, void (MainWindow::*)(int&), int> cbwsPtr(this, &MainWindow::DoWork);
CallbackWrapperBase<int>* cbwbPtr = &cbwsPtr;
cbwbPtr->Execute(i);
cbwbPtr->Execute(i);
}
}
|
|
|
|
|
Is a Rebuild All in order?
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Yep, I've done multiple cleans and rebuilds -- still no luck. I wonder if I've corrupted the memory somewhere... or I need to enable some kind of extra flag for debugging MFC Multithreaded applications, etc.
|
|
|
|
|
Bah, it was just optimizing for maximum speed (which was a default setting) that caused these problems... I turned it off (/Od) and now I can see everything the way I want to for a debug version.
|
|
|
|
|
Cyrilix wrote: Bah, it was just optimizing...
In debug mode?
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Yes, it was the default in debug mode when I created the project.
|
|
|
|
|
<>.,yuutyutyutyu,/,.//,.//,./<.<><<>,<>
';l';l
|
|
|
|
|
Will you stop spamming the forums with your crap please ?
|
|
|
|
|
Dear all
i need your help. in advance i thank u. my issue is as follows:
if i have a menuitem, after i click it, one dialog appears:ask users to enter parameters below: length=10 pixel, width=10pixel, height=10 pixel, then click ok.correspording to cube will show in window. how to program this point? who have any such snippet? so urgent. thanks very much.
regards
zhiyuan
Li Zhiyuan
6/14/2007
|
|
|
|
|
li zhiyuan wrote: who have any such snippet?
My good friend the internet [^] does.
|
|
|
|
|
I am tiered of banging my head against the wall trying to figure this out. So I am here to find out from the experts what the problem might be. The following code:
void CMonthCalCtrlEx::OnMouseMove(UINT nFlags, CPoint point) <br />
{<br />
MCHITTESTINFO mcHitTest;<br />
mcHitTest.cbSize = sizeof(MCHITTESTINFO);<br />
mcHitTest.pt = point;<br />
<br />
switch(HitTest(&mcHitTest))<br />
{<br />
case MCHT_CALENDARDATE:<br />
case MCHT_CALENDARDATENEXT:<br />
case MCHT_CALENDARDATEPREV:<br />
{<br />
if(memcmp(&mcHitTest.st, &m_stOldToolTipDate, sizeof(SYSTEMTIME)))<br />
{<br />
m_tooltip.Activate(TRUE);<br />
<br />
if(m_mapHolidayNames.Lookup(mcHitTest.st.wYear * 10000 + mcHitTest.st.wMonth * 100 + mcHitTest.st.wDay, strToolTip))<br />
{<br />
m_tooltip.Activate(TRUE);<br />
m_tooltip.UpdateTipText(strToolTip, this);<br />
<br />
MSG msg;<br />
msg.hwnd = m_hWnd;<br />
msg.message = WM_MOUSEMOVE;<br />
m_tooltip.RelayEvent(&msg);<br />
}<br />
else<br />
{<br />
ExtndedToolTip(mcHitTest);<br />
m_tooltip.UpdateTipText(strToolTip,this);<br />
MSG msg;<br />
msg.hwnd = m_hWnd;<br />
msg.message = WM_MOUSEMOVE;<br />
m_tooltip.RelayEvent(&msg);<br />
}<br />
}<br />
break;<br />
}<br />
default:<br />
{<br />
memset(&m_stOldToolTipDate, 0, sizeof m_stOldToolTipDate);<br />
m_tooltip.Activate(FALSE);<br />
break;<br />
}<br />
}<br />
CMonthCalCtrl::OnMouseMove(nFlags, point);<br />
}
worked fine under Microsoft Visual C++ 6.0. However, I have upgraded to Visual Studio C++ 2005 and now the code fails. Can anyone please point in in the right direction on how to fix it in VS? Everything compiles ok, but it seems to by pass this MCHITTESTINFO mcHitTest; and does not assign the point value to mcHitTest.pt = point;. So do I have to use some other method for dealing with OnMouseMove in VS? Any help would be appreciated.
Thanks,
Charlie
Everything is Free... Until You Have to Pay for it...
Platforms Windows 2000/XP Professional using Visual C++ 6.0
|
|
|
|
|
I'm not sure if this is the problem, but the point passed to OnMouseMove is in client coordinates.
Is the MCM_HITTEST (HitTest()) message expecting screen coordinates?
Never mind - I tested your code and it worked for me...
Mark
-- modified at 13:39 Wednesday 13th June, 2007
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
Hey,
I've been busy with C++ for many years now, and this particular problem has always been eluding me.
I'm using Visual C++ 6.0, with Service packs 5&6 installed, as well as processor pack 5.
My machine is running Windows XP SP2, and hyperthreading is enabled.
To Illustrate my problem I've created a simple test app. :
In a multi-threaded C++ Application, I have a Parent Dialog, which creates(runs) 2 independent threads.
I have assigned each of the 2 threads, intensive, continuous computational work within a while loop. (The loop criteria is met and breaks when the parent sets a member value requesting them to exit)
This Test : starting and running both threads simultaneously and then shutting them down again, works perfectly, in debug.
However, once I compile and run the project in release, neither of the threads seem to register that the the loop criteria variable has changed.
------------------------------------------------------
Thread Code :
------------------------------------------------------
CTestThread1Dlg* parent = (CTestThread1Dlg*) param;
parent->m_Thread1Running = true;
parent->m_Thread1Starting = false;
while (parent->m_RunThread1)
{
parent->m_Th1Value++;
}
parent->m_Thread1Running = false;
_endthread();
------------------------------------------------------
But this only happens when the thread is using all the computational power that it can get (no interruptions, ie. conditionals, Sleeps, etc).
If I were to introduce a "Sleep(15)" right after the increment, then the thread would immediately register a change in "m_RunThread1" and exit, the moment the parent changes "m_RunThread1".
With the given code above(Thread Code), in release, the thread does not register and break the while loop when I call code from the parent, such as :
------------------------------------------------------
Parent Code :
------------------------------------------------------
m_RunThread1 = false;
Beep(450, 50);
Beep(450, 50);
while (m_Thread1Running || m_Thread1Starting)
Sleep(100);
AfxMessageBox("Thread1 has exited");
------------------------------------------------------
I added the 2 beeps so that I also have audio confirmation that "m_RunThread1", was indeed set - and I hear the beeps, but the threads keep going.
Do the threads have a type of duplicate memory state of all the members that they access, (which are only updated once the thread's CPU time has elapsed, and it is removed from the stack for the next thread)?
That does not make logical sense to me, but it is the only reason that I could think of, explaining why the parents' "parent->m_RunThread1" is not 'updated' until the thread's execution cycle is interrupted...
Has anyone else experienced this behavior?
I've currently pinned down the problem within a huge multi-threaded application, and unless I can identify how to solve it in this simple test case, there is no hope of fixing it :/
Any info. would be appreciated, thanks.
|
|
|
|
|