|
I am writing dll programs to do some file conversions for scientific data. Is there any way for me to do a dyn. memory allocation with out having constants in between the brackets but rather have declared variables.
Here is what I have now..
const int X = 100;
const int Y = 50;
long (*data)[Y];
int x,y;
if (!(pix_data = new long[X][Y])) { printf("Error allocating memory...\n"); return 1; }
I cant figure out a way to have an integer in X and Y that is declared internally (in main()) rather than having 100 or 50. When I place integers, error comes up saying " expected constant expression". Thus, I need not specify 100 or 50 but it looks to other varibles to figure that out. I have looked everywhere..
Any help is appreciated.
|
|
|
|
|
aero6dyn wrote:
const int X = 100;
const int Y = 50;
long (*data)[Y];
int x,y;
if (!(pix_data = new long[X][Y])) { printf("Error allocating memory...\n"); return 1; }
change to
const int X = 100;
const int Y = 50;
long (*data)[Y];
int x,y;
if (!(pix_data = new long[X * Y])) { printf("Error allocating memory...\n"); return 1; }
for the memory allocation and it should be fine.
Rob Manderson
I'm working on a version for Visual Lisp++
|
|
|
|
|
Thanks for the help. Rob..
Although, allocating isnt the issue I am having. Sorry, maybe I wasnt clear with my concern.I want to stay away from having to write:
const int X = 100;
const int Y = 50;
I have internal variables in main() that are assigned the values of 100 and 50. Thus, I would like to use them instead of having constants or define statements.. I want something like
int X = row_size;
int Y = column_size;
Ofcourse, that gives me an error saying "expected constant expression" at the line
long (*data)[Y];
This is because I am guessing c++ needs to know the size of the array before it starts compiling instead of looking in main().
I will have different files w/ different row_sizes and column_sizes so I cant have 100 or 50. So no input by the user specifying the # of rows or columns for each file I call is necessary.
Does that make any sense....
|
|
|
|
|
I am working on simple visual recognition program.
I have two bitmaps - background and background plus unknown object.
I can do convolution to filter out the unknown object, but I cannot figure out how to store the result for further processing.
So far I have same size bitmap with "empty" pixels.
Evetually I'll need to determine the shape of the object and I am looking for some kinda of trace algorithm to save this resulting image.
Thanks for your help Vaclav
|
|
|
|
|
I am trying to do this on my own at home, but have a serious need at work for the following DLL. I can do this in VB unfortunately WinRunner can not use VB DLL's since they are COM servers.
I wrote a simple dll that works but the this project is requires a message box.
I need a c++ dll that
a) I can launch a modalless message box with message passed.
b) keep on top
c) place on screen using x,y
d) close
Can anyone help me? I've never written a c++ dialog before.
thanks all
dhermann@ameriquest.net
|
|
|
|
|
I put a dll on
http://www.immenro.de/test/diadll.dll
you can download it there
the method is called
call_it(int x, int y, int cx, int cy, CString text)
|
|
|
|
|
Is there a way I can perform pointer arithmetic on an iterator? I have a function that goes through a long CString object first and stores the positions of the spaces in a vector<int> object. Going through the normal steps of iterating through each, I am able to get single words, and that works fine. However, the user will have to be able to specify how many words they want extracted at a time, which is held in m_nWordCount. right now I have something like this:
for(iter = intVec.begin(); iter != intVec.end(); )
{
nTemp = *iter;
iter++;
int nTemp2 = *iter;
nTemp++;
strWord = strTemp.Mid(nTemp ,nTemp2 - nTemp);
sWord.word = strWord.Trim();
if(sWord.word.GetLength() > 0)
::vecWords.push_back(sWord);
}
the problem line above is in bold (although it works for one word)
what I want to be able to do is this:
int nTemp2 = *(iter + m_nWordCount);
so that if the user specified 2 as the word count it would get whatever the value is at 2 spaces up.
(first position is 0, second is 5, third is 12)
this would allow them to get the string from position 0 to 12)
of course then I would also have to put my iterator incrementation back in the 'for' loop declaration
Thanks In Advance;)
If it's broken, I probably did it
bdiamond
|
|
|
|
|
Sorry, I seem to have found the answer, except for one problem. If I put this it works:
vector<int>::iterator tempIter = iter + 2;
but this doesn't:
vector<int>::iterator tempIter = iter + m_nWordCount;
I get this error when I try to use the variable instead of the hard-coded number:
error C2678: binary '+' : no operator found which takes a left-hand operand of type 'std::vector<_Ty>::iterator' (or there is no acceptable conversion)
If it's broken, I probably did it
bdiamond
|
|
|
|
|
duh! I was trying to use a CString variable
If it's broken, I probably did it
bdiamond
|
|
|
|
|
It sounds like when you are iterating through the string, you need to keep a count (N) of how many word breaks have been found so far. If that count is evenly divisible by m_nWordCount , add what has been found up to that point to the array and reset the count N. Make sense?
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
Hi everybody.
I have a simple question.
I have a CByteArray object and I need to convert it to a VARIANT, how could I do that.
|
|
|
|
|
Hi Roger,
Well... there is probably a nicer way, but if you're using MFC you could do:
VARIANT aVariant = COleVariant(myByteArray).Detach();
It's a bit lazy, but hey...
|
|
|
|
|
Hi everybody.
I have a simple question.
I have a CByteArray object and I need to convert it to a VARIANT, how could I do that.
|
|
|
|
|
Does anyone have experience of automating this (ActiveX or not) ?
I am thinking of producing a little DJing application (using MP3) and this has the best codec by far.
I've already looked at MSDN but information is a bit short there - getting current position etc..
Ta.
Elaine
The tigress is here
|
|
|
|
|
|
|
Has anyone created a class to use a Date/Time picker in a cell of a CListCtrl ?
Cheers,
Andy
|
|
|
|
|
Hello.
First, I'd like you to take a look at this post from another forum: http://www.codeguru.com/forum/showthread.php?s=4f35cbebe00b8299d7c4f45da97051c1&threadid=193904 (it explains the problem with CSerialPort -- this should also be brought to the attention of the authors of the class)
Anyway, I came across the exact same problem, except I was not using the class. I simply had WaitCommEvent and GetLastError() give me the same error 87 using this piece of code:
if (WaitCommEvent(hCom, &event, &obj))
{
cout << "Character Detected! ";
fsuccess = ReadFile (hCom, &data, 1, &transferred, &obj);
if (fsuccess)
cout << "Character Read! Here it is: " << data;
getch();
}
else
{
if (GetLastError() == ERROR_IO_PENDING)
cout << "Still waiting";
else
{
cout << "Fatal error: " << GetLastError();
getch();
exit(1);
}
}
As I said, the output for this program is Fatal error: 87. I should explain, this is after the COM1 port has been opened successfully for reading. Does anyone have any suggestions as to how to solve this? I will be very thankful if someone could help.
Thanks..
|
|
|
|
|
|
I am receiving a struct which has floats, int etc. I use ntohl etc on the ints and it all works fine. But on the floats, I am not sure what to use to get the bits in the right order. I had thought that ntohl will take any 32 bit number and convert it but I know when I use it, it does not convert it correctly. I tried to convert it myself one bit at a time and it is OK. Is there an easier way with a call already done?
Thanks in advance.
|
|
|
|
|
float floatVal =
unsigned long *longPtr = (unsigned long*)&floatVal;
*longPtr = ntohl(*longPtr);
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"
|
|
|
|
|
I have a question regarding standard out. I would like to re-direct standard out to a pipe. To connect to the pipe, I use CreateFile. Then, I must use WriteFile to send over the pipe. Is there a way to do this without the WriteFile call. Instead, simply redirect the standard out stream to the Pipe.
|
|
|
|
|
As everything in Windows are represented by handles, you can use GetStdHandle and SetStdHandle to operate on the standard stream handles (file handles). Just use CreateFile to create and connect the pipe, then use SetStdHandle with appropriate parameters to redirect the standard stream into the pipe.
These functions will redirect the standard streams or get their handles for the current process only. So for all other processes, the streams remain normal. But it's good practise nevertheless to first use GetStdHandle , save it, and restore it back after you're done.
-Antti Keskinen
----------------------------------------------
The definition of impossible is strictly dependant
on what we think is possible.
|
|
|
|
|
Hi.. I have an application that create the thread at PRINT button is clicked, and stop the thread when STOP PRINTING button is clicked.
<br />
UINT PrintFile(LPVOID lParam)<br />
{<br />
myApp *cc=(myApp*)lParam;<br />
while(!stopprinting)<br />
{ <br />
if(stopprinting)<br />
{ <br />
break;<br />
}<br />
cc->myClass->Print()<br />
} <br />
return 0;<br />
}<br />
<br />
void myApp::print()<br />
{<br />
....<br />
CWinThread *printingThread; <br />
printingThread = AfxBeginThread(PrintFile,this);<br />
printingThread->m_bAutoDelete = FALSE;<br />
}<br />
then I have a class called myClass in the same application. myClass print the files, it ofcourse, has other functions except Print().
Ok here how Print() does print the file
<br />
void myClass::Print()<br />
{<br />
for(int i=0;i<10;i++) <br />
{<br />
CString f= array[i];<br />
PrintFile(f);
finishedprinting = false;<br />
WaitForFilePrinted();<br />
finifhsedprinting = true;<br />
<br />
}<br />
}<br />
The printer server send the window messages when the file starts and ends printing doc, to application and myApp catch those messages. I had to used RegisterWindowMessage() and in MessageMap
I add following statement,
ON_REGISTERED_MESSAGE(BlackIcePrintMessage,OnPrinterMsg)
and then OnPrinterMsg() catch the messages and do something when the document get started printing, and ended printing. when the document get printed, finishedPrinting get set to true
<br />
finishedprinting = true;<br />
I want my application to be continue on the next file if and only if finishedprinting = true.
so I wrote following function to wait for the file to really get printed.
<br />
UINT WaitForFilePrinted(LPVOID lParam)<br />
{<br />
myClass *cc=(myClass*)lParam;<br />
while(!finishedprinting)<br />
{ <br />
if(finishedprinting)<br />
{ <br />
break;<br />
}<br />
cc->WaitForPrinter();<br />
} <br />
AfxEndThread(1); <br />
return 0;<br />
}<br />
void myClass::WaitForFilePrinted(void)<br />
{<br />
CWinThread *printingThread; <br />
printingThread = AfxBeginThread(WaitForFilePrinted,this);<br />
printingThread->m_bAutoDelete = FALSE;<br />
<br />
}<br />
<br />
void myClass::WaitForPrinter(void)<br />
{<br />
while(!finishedprinting)<br />
Sleep(500);<br />
}<br />
I'm not sure I'm doing the right thing. And it is seems like thread inside another thread. it is not doing what I want to do..and I got access error. All I want is that
send the file to the printer..
wait for the messages from the printer..
when I get the message that the printer said the file get printed.. send next file
keep the same process, untill all the files gets printed.
could you please give me some suggestion how should I pause myApp so it will wait for the file just send to printer gets printed and then move on next one?
thank you
|
|
|
|
|
Too much code. Just succinctly explain what you want to accomplish.
Kuphryn
|
|
|
|