|
There are many ways of doing it. Some easier than others, it all depends on what you want. If all you want is a line drawn from top to bottom then what I would try is using a borderless, one pixel wide child window that sits on top of the view. If you want anything more complicated then you will have to start drawing the view yourself, not a simple task.
It's not rocket surgery!
Within you lies the power for good, use it!!!
|
|
|
|
|
Hi,
I want to use methods in an activex component (.ocx) file in C++;
In VB I simply used Set obj=CreateObject("MSScriptControl.ScriptControl")
I don't know how should I do the same (either LateBonding or EralyBonding) in C++.
I'd be glad if someone could help me out!
|
|
|
|
|
|
hi once again... tnx for the answers to my previous posts...
again i have another qxn to ask...
will the code below post any memory leak or any pointer problems?
i am unsure as how to write the code for a struct to have an indefinite size of array of structs inside it. so what i did is to just use a pointer and have a member which holds the size of the array pointed to. is there any efficient way to go about this? tnx a lot!
typedef struct
{
int number;
int number2;
} TEST, *LPTEST;
typedef struct
{
LPTEST pTest;
int number;
} TEST_CONT;
TEST test[2];
test[0].number = 123;
test[0].number2 = 45;
test[1].number = 678;
test[1].number2 = 910;
TEST_CONT testC;
testC.pTest = test;
testC.number = 98765;
int n = testC.pTest[0].number;
int n2 = testC.pTest[0].number2;
cout << n << " " << n2 << " " << testC.number << endl;
n = testC.pTest[1].number;
n2 = testC.pTest[1].number2;
cout << n << " " << n2 << " " << testC.number << endl;
newbie
|
|
|
|
|
No memory leak in the code just because there is no object created by 'new'.
TEST_CONT testC;
testC.pTest = test;
testC.number = 98765;
here testC.number should be the number of elements of the test, right? So why 98765?
C++ provides std::vector class which is a dynamically growing array. You might use it like so;
typedef struct
{
std::vector<test> tests;
} TEST_CONT;
TEST_CONT testC;
testC.tests.push_back(test);
//...
int n = testC.tests[0].number;
int n2 = testC.tests[0].number2;
cout << n << " " << n2 << " " << testC.tests.size()<< endl;
--
=====
Arman
|
|
|
|
|
hi Arman! tnx for the reply.
oooppss... yes that should be the count... i had that in mind but when i was trying out the code didnt really put it in the implementation...
tnx for the suggestion regarding vector... i'll consider it.
again tnx!
newbie
|
|
|
|
|
Hi,
I have a Byte buffer. I need to keep on appending buffers to my initial buffer. How to do it?Any suggestions would be helpful.
Thanks
Today is a gift, that's why it is called the present.
|
|
|
|
|
Why not;
CByteArray array;
array.Add( myByteValue );
--
=====
Arman
|
|
|
|
|
It depends on the language used, but seeing as this is mainly a C++ forum.
The STL provides the ‘vector’ class for creating dynamic buffers.
The MFC provides different containers for doing the same thing, including CByteArray.
If you where writing it in C, then you would have to create your own method for doing the same thing. Usually dependant on a structure pointer (or handle), if done right, that is passed to the required functions.
INTP
"Program testing can be used to show the presence of bugs, but never to show their absence."Edsger Dijkstra
|
|
|
|
|
how do i tell the OS that i want to handle the WM_DESTROY message without clicking the close button. This is what i m trying to do :
I must launch the application, it must play a wav sound and the app must close automatically without hiting the close button in the title bar.
Thanks in Advance,
Sumit Mandal
|
|
|
|
|
Is PostQuitMessage of any help?
|
|
|
|
|
If all your application does it play a sound then exit why does it need a window at all?
Steve
|
|
|
|
|
Post a WM_CLOSE message to your main window.
|
|
|
|
|
Hello everyone !!!!
I am programming Win32 environment(VC++6).I have a file name(e.g : Text.txt),i want to get full path of it .
Please help me
Thanks .
|
|
|
|
|
Im not sure but is your answer
CFileDialog> class <br />
<br />
<div class="ForumSig"><div style="padding: 0; margin: 0; background-color: rgba(170, 214, 255, 1); text-align: center; font-family: Arial; font-weight: bold; font-style: italic; font-size: 9pt"><br />
<div style="color: rgba(255, 255, 255, 1); width: 300px"><br />
<hr width="250" size="7">WhiteSky<hr width="220" size="7"></div></div></div>
|
|
|
|
|
Use CString path=Path::GetFullPath("Text.txt");
Proud To Be an Indian
|
|
|
|
|
1. Why Interlocked functions not have only-read operating funciton?
2.Interlocked function working at value A, at the same time other thread a function read value A, who first pass? If i want fist read operation then write operation, how to do?
3.example 1:
more thread1 run, but i want only and only run first thread1 can do (1) until ReWork function run. Can those code good work?
volatile LONG g_bLock = FALSE;<br />
<br />
VOID thread1()<br />
{<br />
if (!g_bLock)<br />
{<br />
InterlockedExchange(&g_bLock, TRUE);<br />
<br />
(1)<br />
}<br />
}<br />
<br />
VOID ReWork()<br />
{<br />
InterlockedExchange(&g_bLock, FALSE);<br />
}
Thanks.
|
|
|
|
|
1. Why Interlocked functions not have only-read operating funciton?
This is almost meaningless to have such a function. Why? Because
1) Reading is itself not an issue of concurrent accesses (I mean if you only read, you will have no problems)
2) You still can simulate it by those interlocked functions.
2.Interlocked function working at value A, at the same time other thread a function read value A, who first pass?
No one knows. This is impossible to state this or that thread will access the same resource first if they try it concurrently.
If i want fist read operation then write operation, how to do?
Then you have to use some synchronization between the reading and writting threads. Here would be appropriate the usage of Events. See here[^] for more details.
3.example 1:
more thread1 run, but i want only and only run first thread1 can do (1) until ReWork function run. Can those code good work?
Again a synchronization job. Refer to the article cited above.
--
=====
Arman
|
|
|
|
|
If you want to use Interlocked*() to do locking then read about SpinLocks.
A very simple version might look something like (note: doesn't suppport timeout, non-reentrant, doesn't enforce thread ownership, ...):
class SpinLock
{
volatile long lock;
public:
SpinLock( void ) : lock(0) {;}
void Aquire ( void ) {
while( InterlockedCompareExchange(&lock, 1, 0) ) {
SwitchToThread();
}
}
void Release ( void ) {
lock = 0;
}
};
...cmk
Save the whales - collect the whole set
|
|
|
|
|
void Release ( void ) { lock = 0; }
why not use:
InterlockedExchange(&lock, 0);
I think that it's better. isn't?
|
|
|
|
|
|
Sorry, my bad englist...
Umm, your meaning is if the code is a instruction, unneed use Interlocked functions? it unable happen some question?
If "lock = 0" modification "if (0 == lock)", need Interlocked functions?
and i want let nether code safe in multithreading, how to do?
if (0 == lock)
{
lock = 1;
}
else
{
lock = 0;
}
Thanks very much for your answer.
|
|
|
|
|
Interlocked* is needed if you want to do 2 or more things with the value.
In your example:
if( 0 == lock ) lock = 1;
else lock = 0;
You are doing (at least) 2 things:
1. if( 0 == lock )
2. lock = ...;
Imagine 2 threads, Thread1 and Thread2.
Start with lock = 0.
Thread1 checks 1. above: if( 0 == lock ) and returns true
Thread2 then checks 1. above: if( 0 == lock ) and returns true
Thread1 then does 2. above: lock = 1
Thread2 then does 2. above: lock = 1
Problem: both threads think they are locked.
You must use Interlocked* to make it like 1 instruction (i.e. atomic):
InterlockedCompareExchange(&lock, 1, 0)
...cmk
Save the whales - collect the whole set
|
|
|
|
|
volatile bool Sentinel = true;<br />
<br />
unsigned ThreadFunc1( void* pArguments ) {<br />
while (Sentinel){;}<br />
<br />
......<br />
return 0;<br />
} <br />
<br />
unsigned ThreadFunc2( void* pArguments ) {<br />
Sentinel = false;
return 0;<br />
}
--------------------------------------------
Ago, i think if a thread readning a address, and other thread write this address, that will be conflict. But why above not happen error and crash.
you say "You are doing (at least) 2 things", but InterlockedExchange only 1 operation, how to use it.
underside is my some code, can u help me see is it safe?
1.
volatile LONG g_Value = -1;<br />
<br />
LONG Read()<br />
{<br />
......<br />
return InterlockedExchange(&g_Value, g_Value);<br />
}<br />
<br />
VOID Write(LONG NewValue)<br />
{<br />
......<br />
return InterlockedExchange(&g_Value, NewValue);<br />
}<br />
<br />
VOID Thread1()<br />
{<br />
if (Read >= 0)<br />
{<br />
Write(-1);<br />
<br />
for (INT i = 0; i < 10; i++)<br />
{<br />
Write(i);<br />
if (RunThread3() == error)<br />
{<br />
Write(-1);<br />
}<br />
}<br />
}<br />
}<br />
<br />
VOID Thread2()<br />
{<br />
}
-----------------------------------------------------
2.
volatile LONG g_nIndex = -1;<br />
<br />
VOID Thread1()<br />
{<br />
InterlockedExchange(&g_nIndex, 1);<br />
}<br />
<br />
VOID Thread2()<br />
{<br />
do<br />
{<br />
}<br />
while (InterlockedExchange(&g_nIndex, g_nIndex) < -1);<br />
}<br />
<br />
VOID Thread3()<br />
{<br />
INT nIndex = GetIndex();<br />
InterlockedExchange(&g_nIndex, nIndex);<br />
}
-----------------------------------------------------
3.
volatile LONG g_nData1 = 0L;<br />
<br />
VOID Thread1()<br />
{<br />
if (InterlockedExchange(&g_nData1, g_nData1) == 0)<br />
{<br />
InterlockedExchangePointer(&g_nData1, 1);<br />
}<br />
<br />
.................<br />
<br />
if (InterlockedExchangePointer(&g_nData1, g_nData1) == 1)<br />
{<br />
InterlockedExchangePointer(&g_nData1, 0L);<br />
}<br />
}<br />
<br />
VOID Thread2()<br />
{<br />
}
-------------------------------------------------------
4.
volatile LONG g_bIsLock = 0L;<br />
<br />
VOID Thread1()<br />
{<br />
if (InterlockedExchange(&g_bIsLock, g_bIsLock) == 1)<br />
{<br />
InterlockedExchange(&g_bIsLock, 0L);<br />
}<br />
else<br />
{<br />
InterlockedExchange(&g_bIsLock, 1);<br />
}<br />
}<br />
<br />
VOID Thread2()<br />
{<br />
InterlockedExchange(&g_bIsLock, g_bIsLock);<br />
}<br />
<br />
VOID Thread3()<br />
{<br />
if (InterlockedExchange(&g_bIsLock, g_bIsLock))<br />
{<br />
<br />
}<br />
}
Thanks very much for your help.
|
|
|
|
|
Your code does not make sense.
Do not use:
if( InterlockedExchange() ) {
InterlockedExchange();
}
This is bad, you are doing 2 things (test and set) in 2 instructions.
Instead use:
while( InterlockedCompareExchange(&lock, 1, 0) ) {
// lock was == 0, now == 1, 'this' thread set lock = 1
}
This is better, you are doing 2 things in 1 instruction.
...cmk
Save the whales - collect the whole set
|
|
|
|