|
no, field is text type and its max lenght is 255,but i always enter data less than 255
|
|
|
|
|
Le@rner wrote: please help me how can i resolve this error.
By using the debugger to step through the code, looking at the values of variables along the way.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
Hi All!
Probably will go better on the WinAPI section but since there is an ASM part i'm a bit confused of where to put it, and seen that i use gcc...heeelp!! :P
I'm just getting mad, i'm tryng to build a lock-free messaging system with the usage of atomic instructions. And yes i could use boost but i'll lose the interesting part of the whole thing :P
I actually work on windows (hence the Interlock...) with CodeBlocks and the gcc bundled with him on a dual core PC
I instantiated a class with
class ZTest{
public:
volatile LONG varToCheck;
}
And then i try to something like this (using a member variable of a class created with new)
ZTest *zt=new ZTest();
InterlockCompareExchange(&zt->varToCheck,DEFINE_ONE,DEFINE_TWO);
All the time, while in debug i obtain a segmentation fault... someone said that i should have not used the debug build, i then tryed with the release, removing all optimizations (just to be sure), but after 20/30 iteration over the Interlock... function everything explode...with a segmentation fault..
Reaching the limit of my wrath...i tried with assembly with the LOCK CMPXCHG instruction and... after 20/30 iteration guess what? A segmentation fault
Now, i guess something is totally worng with this, tomorrow i'll try with M$ compiler to check if it's only a gcc fault (i doubt but...)
Does someone ever tryed something like this?
Any suggestion, question and request clarification will be welcome...
Zak...ah, yes i think i'll get soon a segmentation fault myself...
|
|
|
|
|
MSDN says:[^]
The parameters for this function must be aligned on a 32-bit boundary; otherwise, the function will behave unpredictably on multiprocessor x86 systems and any non-x86 systems.
What is the value of __alignof__ (varToCheck); ?
|
|
|
|
|
 Hi!
Firstly thank you for the answer! I did'nt even knew that existed this keyword!!
The variables seems aligned to 4 bytes, that is 32 bit so it should be fine, as far as i know (that is honestly really a little...).
I tried using pointer variables as member variables, allocating them (with sizeof(variable)+4)and taking an address in the mallocated area that was aligned...and everything concluded with segmentation...
There is something that i don't quite understand into this...
Thank you!
Zak
---EDIT---
Now i tryed with a snippet took from MSDN about porting from Unix... and everything works as expected...same compiler options...same everything. Even the alignement of the variables used is ok....
#include <iostream>
using namespace std;
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
class Pippo{
LONG pappa;
public:
LONG pippe;
char test;
LONG new_value;
VOID doStuff(){
printf("fuffa\r\n");
};
};
DWORD WINAPI thread_function(PVOID arg)
{
int count2;
Pippo*pipp = (Pippo*)arg;
printf("thread_function is running. %d\r\n",__alignof__(pipp->new_value));
for (count2 = 0; count2 < 1000; count2++) {
Sleep(10);
printf("(T-%d)", pipp->new_value);
InterlockedExchange(&pipp->new_value, 1);
}
Sleep(3000);
return 0;
}
int main()
{
HANDLE a_thread;
DWORD a_threadId;
DWORD thread_result;
int count1;
Pippo* pipp=new Pippo();
pipp->new_value=1;
a_thread = CreateThread(NULL, 0, thread_function, (PVOID)pipp,0, &a_threadId);
if (a_thread == NULL) {
perror("Thread creation failed");
exit(EXIT_FAILURE);
}
printf("entering loop\n");
for (count1 = 0; count1 < 10000; count1++) {
Sleep(1);
printf("(P-%d)", pipp->new_value);
InterlockedExchange(&pipp->new_value, 2);
}
printf("\nWaiting for thread to finish...\n");
if (WaitForSingleObject(a_thread, INFINITE) != WAIT_OBJECT_0) {
perror("Thread join failed");
exit(EXIT_FAILURE);
}
GetExitCodeThread(a_thread, &thread_result);
printf("\nThread joined\n");
exit(EXIT_SUCCESS);
return 0;
}
modified on Thursday, November 4, 2010 4:48 AM
|
|
|
|
|
Not really part of the thread, but I would be interested in the algorithm you're gonna use for your lock free queue... may you share a pointer to that?
|
|
|
|
|
What the !###$@#$
I was passing the class that contains the variable to use inside the interlock functions to the CreateThread function for the "child" threads, but before that i was putting them into an stl list...
For who know what reason (may be i forgot the copy constructors etc. inside the class to put into the std::list container ) the class i were getting FROM the list was "clean" as just created...with the variables for the interlock uninitialized...and then CRASH!!!!
Thank you for the suggestions...and always remember the "not so ancillary" methods...
Zal
|
|
|
|
|
This is a basic COM Compound Document or Structured Storage question.
I created an IStream within an IStorage and wrote four of these (each four bytes) to that IStream…
typedef struct tagINDEX
{
DWORD dwPlotRecord;
}INDEX;
The Storage was created like so…
wchar_t szFile[]=L"C:\\Code\\VStudio\\VC++6\\Projects\\COM\\CompStor\\CmpStr07\\Release\\Data.dat";
IStorage* pStorage=NULL;
DWORD grfMode;
HRESULT hr;
grfMode=STGM_SIMPLE | STGM_CREATE | STGM_READWRITE | STGM_SHARE_EXCLUSIVE ;
hr=StgCreateDocfile(szFile,grfMode,0,&pStorage);
I can read those four records out of my IStream using IStream::Read() but have been unable to determine the correct byte count of the four records (each four bytes) I wrote in with IStream::Write(). Since each INDEX record is four bytes and I wrote four such records ‘in’, then I’d hope to obtain an…
IStream::Stat(STATSTG*, STATFLAG_NONAME)
…return where the STATSTG.cbSize.LowPart would equal 16. This is not what is returned to me, but rather the number 4096, which looks suspiciously to me like a sector size, which I’m further assumming was the initial memory/file allocation for the IStream.
It does not appear to me that Streams have an analogous function to the Windows Base Services GetFileSize() Api. Does anyone know anything about this? How do you get the number of bytes actually written to a Stream as opposed to the total allocation for the Stream? I'm just teaching myself COM Compound Document Storage Interfaces, and was doing rather well until I hit this problem!
I'll provide some additional information.
Here is what got written into a Simple IStream...
Now Try To Put Data In Structured Storage!
szFile = C:\Code\VStudio\VC++6\Projects\COM\CompStor\CmpStr07\Release\Data.dat
StgCreateDocFile() Succeeded!
pStorage->CreateStream(Index) Succeeded!
Will Now Try To Write Index Records To Structured Storage
dwNumPlots = 4
i idx.dwPlotRecord pcbWritten
=========================================
1 1 4
2 3 4
3 4 4
4 5 4
After having written those 16 bytes and Releasing() both pStream and pStorage, then re-opening both, that's where I ran into the difficulty. Here is a short program with output afterward showing that even S_OK is returned by reading past the original 16 byte IStream::Write()...
#include <objbase.h>
#include <stdio.h>
#include <string.h>
typedef struct tagINDEX
{
DWORD dwPlotRecord;
}INDEX;
int main(void)
{
wchar_t szFile[]=L"C:\\Code\\VStudio\\VC++6\\Projects\\COM\\CompStor\\CmpStr08\\Release\\Data.dat";
IStream* pIdxStream=NULL;
IStorage* pStorage=NULL;
char szBuffer[128];
ULONG pcbRead=0;
DWORD grfMode;
STATSTG sts;
unsigned i;
HRESULT hr;
INDEX idx;
wprintf(L"szFile = %s\n",szFile);
grfMode=STGM_SIMPLE | STGM_READ | STGM_SHARE_EXCLUSIVE;
hr=StgOpenStorage(szFile,NULL,grfMode,NULL,0,&pStorage);
if(SUCCEEDED(hr))
{
printf("StgOpenStorage() Succeeded!\n");
hr=pStorage->OpenStream(L"Index", NULL, STGM_READ | STGM_SHARE_EXCLUSIVE, 0, &pIdxStream);
if(SUCCEEDED(hr))
{
printf("pStorage->OpenStream(Index) Succeeded!\n");
hr=pIdxStream->Stat(&sts,1);
if(SUCCEEDED(hr))
{
printf("pIdxStream->Stat(&sts,1) Succeeded!\n");
printf("sts.cbSize.LowPart = %u\n",sts.cbSize.LowPart);
printf("sts.cbSize.HighPart = %u\n",sts.cbSize.HighPart);
}
printf("\ni\tpcbRead\tidx.dwPlotRecord\tHRESULT\n");
printf("===============================================\n");
for(i=1; i<=8; i++)
{
hr=pIdxStream->Read(&idx,sizeof(INDEX),&pcbRead);
switch(hr)
{
case S_OK:
strcpy(szBuffer,"S_OK");
break;
case S_FALSE:
strcpy(szBuffer,"S_FALSE");
break;
default:
strcpy(szBuffer,"Don't Know What hr Means!");
break;
}
printf("%u\t%u\t%u\t\t\t%s\n",i,pcbRead,idx.dwPlotRecord,szBuffer);
}
pIdxStream->Release();
}
pStorage->Release();
}
getchar();
return 0;
}
modified on Wednesday, November 3, 2010 4:36 PM
|
|
|
|
|
Frederick J. Harris wrote: How do you get the number of bytes actually written to a Stream as opposed to the total allocation for the Stream?
I'm not sure you can. I've just looked at the source for an MMC snap-in we have, and that uses streams to store and retrieve the console state. We needed to store some binary data, so we wrote out the length of the data, as a four-byte long, and then the data itself. On reading, we read the first four bytes (which we know will be there), and then use that to determine how much more data to read.
|
|
|
|
|
Thanks for the feedback Electron. Been mulling over the problem and it occurred to me I may not be able to use the STGM_SIMPLE flag in the STGM parameter, but may need to use the full transacted mode (with ::Commit() to get record counts to work. I'll read up on it this evening, and maybe try it again tomorrow. It would be neat to get this to work. If structured storage has this limitation, its going to be useless to me. I'm not ready to give up just yet though. 
|
|
|
|
|
I've studied up on the issue enough to have convinced myself that any further effort to use any system capabilities to determine the count of bytes previously written to an IStream would be fruitless. While Microsoft's documentation does push the analogy that IStreams are pretty much like files, the fact is that the analogy only goes so far. It appears that some file capabilities don't exist for IStreams in compound storage, and I'd guess at this point marking the end of written bytes is one of them. It follows from this that there is nothing akin to a SetEndOfFile().
It occurs to me that these missing capabilities could be coded into an app that uses compound document files, for example creating a seperate IStream to store the actual length of data written into other IStreams.
|
|
|
|
|
Hi all,
i checking the link status some times it takes so much time i want if the link status is not return in 2 min its time out this function and process further commands and functions.
please tell me how can i do this.
thanks in advance.
|
|
|
|
|
|
When I did this, I called HttpSendRequest() in a separate thread. See MSDN article Q224318 for details.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
If you use the nested loop do something. you can count the time, if overtime, show one your timeout excetpion to goto the outest .
|
|
|
|
|
Hi,
How to generate this type of number in header files?
#if !defined(AFX_COL_H__1C5B8C95_F2A0_424C_9CAB_CCF5E76B642E__INCLUDED_)
#define AFX_COL_H__1C5B8C95_F2A0_424C_9CAB_CCF5E76B642E__INCLUDED_
|
|
|
|
|
They are usually generated automatically when you create a new class through the MFC wizard.
On the other hand, you can perfectly attribute one yourself, usually the filename is used in someone (e.g. MYFILE_H). As long as the identifier is unique, its perfectly fine. You can also use the #pragma once directive which has been added in more recent compiler versions.
|
|
|
|
|
To get new GUID s you've to use guidgen tool, see here[^] for the steps required to run the tool from the Visual Studio IDE.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
The other replies must be good enough for you.
Nevertheless, you can do this programmatically using APIs like UuidCreate , UuidCreateSequential etc.
|
|
|
|
|
Thank you!
I thought there might be a way to generate the uid along with the header creation.
In the above all replies we've to get uid separately and then append it to the header macro separately....
|
|
|
|
|
But my visual studio do not output uid insteaded by "#pragma once" 
|
|
|
|
|
Is there any way to find how many instance of an applications are running?
|
|
|
|
|
using EnumWindows API.
Which is give the handle of running applications .
Get window text from from CWnd * wnd and compare text with your application name.
|
|
|
|
|
Click here ->[^]
May be this link will help you..
Yes U Can ...If U Can ,Dream it , U can do it ...ICAN
|
|
|
|
|
As long as your code compiles to an exe, you can do it this way:
- Add the following lines on top of one of your cpp files:
#pragma data_seg("shared")
LONG g_counter = 0; #pragma data_seg()
#pragma comment(linker, "/section:shared,rws") - Execute the following instruction as soon as possible at startup of your application:
InterlockedIncrement(&g_counter); - Execute the following instruction immediately before exiting from your application:
InterlockedDecrement(&g_counter); - When you need the number of instance of your application currently running, use this code:
LONG instances = InterlockedExchangeAdd(&g_counter, 0);
This method works properly only with exe because they are never relocated while loaded; the trick is to create a section whith the read, write and shared attributes and put there a variable used to count the instances. This way that variable is shared between all the instances of your application, and you can use the Interlocked Variable Access[^] functions to safely access the variable.
See also data_seg (C/C++)[^] and /SECTION[^] for more details on how this code works.
|
|
|
|
|