|
That should be a big clue then. Since it is no longer being called, the new code you added is at fault.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"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
|
|
|
|
|
|
Yes. Did you somehow think that once was sufficient? I fully expect to see a similar response to ours shortly.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"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
|
|
|
|
|
|
led mike wrote: It's friday so I'm passing out lots of today!!!
Hey man, I'm waiting.
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]
|
|
|
|
|
Hi,
I have a simple question but I can't find its answer!
"how can I open a TIFF image file and display it?? "
it looks so simple so there is not anywhere about it.
My email: My.wistful@gmail.com
many thanks
|
|
|
|
|
myprojectme wrote: "how can I open a TIFF image file and display it?? "
Display where? Are you using MFC?
|
|
|
|
|
yes, I can use MFC and also any other way to do it.
I want with running my c++ program, a TIFF image in specific address open. that's not important where. any way and where that's possible.
thanks
|
|
|
|
|
[^].
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]
|
|
|
|
|
Have you looked into CImage ?
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"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
|
|
|
|
|
You open it just as you would any other file. Your best bet is to find some shareware that reads the file into a bmp or dib and use the Win32 API (it used to be bitblb or something like that) or use DirectX to display it. If you feel ambitious, get yourself a a copy of the TIFF file spec and parse out the header, image, etc info yourself. The standard is a book called "File Formats" (or something like that). It gives the specs for any image file you can think of. I spent some time parsing .DWG files and it is no fun at all. Get yourself some code from the net to read the TIFF and turn it into aa BMP or DIB. BTW, watch out for compressed image files - stay away from them unless you feel super ambitious
Tom.
|
|
|
|
|
|
Hi
i am creating a project in which i want to use ActiveX Data Object.
The above file is not available in temp folder ..how should i get this file ..
Please provicde the comment. Do i have to install any active x object first
|
|
|
|
|
I'm building an Array2D template class to hold a custom class (I am testing with int to keep things simple)
Unfortunately I keep running into the same brick wall. I'll show some code first and then outline my problem.
Array2D.h
#pragma once
#ifndef INC_ARRAY_2D
#define INC_ARRAY_2D
typedef unsigned int UINT;
template <class T>
class Array2D
{
public:
Array2D(UINT TheWidth, UINT TheHeight)
{
Width = TheWidth;
Height = TheHeight;
ppArrayColumns = new T*[Width];
pArray = new T[Width*Height];
for(UINT i = 0; i < Width; i++)
{
ppArrayColumns[i] = &pArray[i*Height];
}
}
Array2D(UINT Size);
~Array2D();
T* operator[] (UINT Index)
{
return ppArrayColumns[Index];
}
private:
T **ppArrayColumns;
T *pArray;
UINT Width;
UINT Height;
};
#endif
Array2D.cpp
#include "Array2D.h"
template <class T>
Array2D<T>::Array2D(UINT Size)
{
Array2D(Size, Size);
}
template <class T>
Array2D<T>::~Array2D()
{
delete[] *ppArrayColumns;
*ppArrayColumns = 0;
delete[] ppArrayColumns;
ppArrayColumns = 0;
pArray = 0;
}
ppArrayColumns is an array of pointers to type T , of size Width . pArray is an array of type T . The constructor for Array2D sets each element of ppArrayColumns to the address of the appropriate element of pArray . The end result should allow us to access pArray like a regular 2D array, but it doesn't!
Each element of ppArrayColumns only points to one element of pArray . As such, when we use the [] operator, the whole thing falls apart because we've managed to walk into funny memory.
Is there any way I can make ppArrayColumns point to one element of pArray , yet still be able to access the next n elements (where n = Height )
Here is a diagram I have made for reference.[^]
modified on Friday, April 3, 2009 8:46 AM
|
|
|
|
|
If all you want is a 2-d array, then Boost.MultiArray[^] might help.
Otherwise -
Sauce! wrote: Each element of ppArrayColumns only points to one element of pArray. As such, when we use the [] operator, the whole thing falls apart because we've managed to walk into funny memory.
I think you'll find that's the way C/C++ arrays work - they are just pointers really. Your code works fine - when I run this code, it prints out addresses that are 40 bytes apart, which is what I'd expect for rows of 10 ints.
Array2D<int> arr(10, 10);
int main(int, char**)
{
for (int i=0;i<10;++i)
std::cout << (int)arr[i] << std::endl;
return 0;
}
Also - your template class won't really be usable, as your client code won't be able to instantiate the size constructor or destructor - you don't define template class methods in .cpp files!
Also - I don't like your destructor code - I prefer to deexplicitly deallocate the things I allocated rather than going through intermediaries:
~Array2D()
{
delete []ppArrayColumns;
delete [] pArray;
}
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Stuart Dootson wrote:
I think you'll find that's the way C/C++ arrays work - they are just pointers really. Your code works fine - when I run this code, it prints out addresses that are 40 bytes apart, which is what I'd expect for rows of 10 ints.
Array2D<int> arr(10, 10);
int main(int, char**)
{
for (int i=0;i<10;++i)
std::cout << (int)arr[i] << std::endl;
return 0;
}</int>
We seem to have a misunderstanding here.
It's a multi-dimensional array, remember? Here's
main.cpp<br />
<br />
<pre>#include <iostream><br />
#include "Array2D.h"<br />
<br />
typedef unsigned int UINT;<br />
using namespace std;<br />
<br />
int main()<br />
{<br />
UINT width = 3, height = 5;<br />
Array2D<int> *theArray;<br />
theArray = new Array2D<int>(width, height);<br />
<br />
<br />
for(UINT i = 0; i < width; i++)<br />
{<br />
for(UINT j = 0; j < height; j++)<br />
{<br />
cout << " [" << i << "][" << j << "]:";<br />
int temp = 0;<br />
cin >> temp; <br />
*theArray[i][j] = temp;<br />
}<br />
cout << "\n";<br />
}<br />
<br />
for(UINT i = 0; i < width; i++)<br />
{<br />
for(UINT j = 0; j < height; j++)<br />
{<br />
int temp = 0;<br />
temp = *theArray[i][j];<br />
cout << temp << " ";<br />
}<br />
cout << "\n";<br />
}<br />
<br />
return 0;<br />
}</pre><br />
You'll find that we are able to assign <code>temp to *theArray[i][j] fine for values [0][0] through [0][3] , however as soon as we attempt to access [1][0] then an access violation occurs. This happens for the reasons I stated in my initial post.
Stuart Dootson wrote: Also - your template class won't really be usable, as your client code won't be able to instantiate the size constructor or destructor - you don't define template class methods in .cpp files!
Ah, I was only getting link errors for the Array2D(Width, Height) constructor and operator[] so I figured those were the only ones that needed to be moved to the .h file. Can anyone link me to a good article that explains why template functions must be defined in the header?
modified on Friday, April 3, 2009 10:24 AM
|
|
|
|
|
Sauce! wrote: *theArray[i][j]
why the * - the dereference is implied when you use array indexing.
Sauce! wrote: Can anyone link me to a good article that explains why template functions must be defined in the header
It's basically because when you instantiate a template, that's when the compiler compiles the template class methods. All the compiler can see at that point is what's in the header file.
This page[^] has a reasonable explanation.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Stuart Dootson wrote: why the * - the dereference is implied when you use array indexing.
Error 1 error C2440: '=' : cannot convert from 'int' to 'int *' c:\users\bryce\documents\visual studio 2008\projects\array2d\array2d\main.cpp 20
visual studio tells me otherwise
The real reason is that theArray is a pointer to an object of type Array2D . Re-read the code and it makes sense.
You were helpful though, I recall that the [] operator has a higher precedence than * . Adding brackets like fixes it... to a point. I'm now able to move through a few more elements of the array without crashing, but I'll have to do more debugging before I can find out why. Most likely [i] and [j] need to be swapped.
The two lines you were talking about should become (*theArray)[i][j] = temp; and temp = (*theArray)[i][j];
Thanks for the help, I'll edit this when I know more information.
edit: as suspected, j and i were simply swapped with each other Code works 100% now
modified on Saturday, April 4, 2009 2:42 AM
|
|
|
|
|
Sauce! wrote: Error 1 error C2440: '=' : cannot convert from 'int' to 'int *' c:\users\bryce\documents\visual studio 2008\projects\array2d\array2d\main.cpp 20
visual studio tells me otherwise
The real reason is that theArray is a pointer to an object of type Array2D. Re-read the code and it makes sense.
So it is
I rarely use unmanaged (in the smart pointer/RAII sense of managed, not the .NET sense of managed!) pointers, especially in a case like that, when the object contains pointers to allocated items. I'd just code it like this:
Array2D<int> theArray(width, height);
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
The reason I've done it this way is because Array2D (not in my test project here, but in the project it was intended for) is used as a member variable for a user-defined class. Array2D expects a width and height as arguments to the constructor. Consider:
class someclass
{
public:
someclass();
~someclass();
private:
Array2D<int> *myArray;
};
someclass::someclass(UINT width, UINT height)
{
myArray = new Array2D<int>(width, height);
}
someclass::~someclass()
{
delete myArray;
}
alternatively...
class someclass
{
public:
someclass(UINT width, UINT height):myArray<int>(width)(height);
~someclass();
private:
Array2D<int> myArray;
};
someclass::~someclass()
{
}
I'm really not a fan of the second snippet. It just comes down to preference really. Unfortunately that means I have to pay the price and place brackets around the dereference operator to override operator precedence like so; (*myArray)[x][y]
|
|
|
|
|
IMO, just keep one array of Width*Height and have an accessor function with row and column as parameter and just return the item at the appropriate position.
Something like that.
T* = pArray[column * Height + row];
This signature was proudly tested on animals.
|
|
|
|
|
Reading the answers, your problem has been solved.
I just wanted to thank you for possibly the best written question I've seen! Even with a diagram...
Iain.
In the process of moving to Sweden for love (awwww).
If you're in Scandinavia and want an MVP on the payroll (or happy with a remote worker), give me a job!
|
|
|
|
|
I figure if I don't put any effort in, then my chances of getting a decent answer are pretty low. I try my best to offset some of the terribly-worded questions you see around here. Not to mention the terrible questions!
Thanks to everyone for the help
|
|
|
|
|
Hi,
I need to create an Executable for my MFC AppWizard(dll) project. This is to debug my program. This is a new program and has no idée how to create an Executable. Other existing programs are easy to debug as they have an .exe file link to the .dll. Please, any help would be appreciated.
|
|
|
|
|
Your query is confusing. My best guess is that you're writing a dynamic link library and you do not know how to debug it.
If I'm right, then just try executing the library from within the IDE like you would execute a normal .exe (F5, Ctrl+F5) and the IDE must ask the executable that would be loading this DLL and it would run that executable.
As soon as that executable executes code from within your DLL, the debugger will get activated and you can debug your DLL (break points, you know).
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|