|
|
Do a thurough search of MSDN, there was and still may be a sample program (dibview or some thing) that did what you are looking for (in C). If you are willing to do a bit of reverse enginering, then take a look at some of the articles at codeproject. Since MFC are just wrapers for the SDK (written in C), they can (for the most part) be reduced to C. Otherwise you need to look at how a bitmap file is layed out and go from there. One other place you can look for code is "sourceforge".
Every thing you need to know about bitmaps (.bmp) is actualy in the MSDN library.
P.S. Do not for get about the function LoadImage(), which was new when Win95 came out.
INTP
|
|
|
|
|
I am getting this assertion when i start my application
File: dbgheap.c
Expression : _CrtIsValidHeapPointer(pUserData)
Compiler causes assertion when i am deleting an array, array is being created and deleted in
right way the strange thing is that i am getting this assertion not every time i run my programme
required help in this regard
|
|
|
|
|
are you doing any allocation at the start of the program?
MSN Messenger.
prakashnadar@msn.com
|
|
|
|
|
My project contains a process which should save a Bitmap with 24 bit colordepth.
First we developed this program for 32 bit and then we wanted to change the program into a 24 bit version
That seems to be kind of difficult.
As far as I know there are 2 changes needed:
- the bitmaparray (array which contains the color values) is the size of the image times 3 (It was times 4 at 32 bit)
- In the bitmap header there is one bitmap depth variable
--> set to 24 bit
well, if I change these 2 things the result varies
Once the bitmap contains a totally distorted picture, another time the pixel lines are alternatingly red, green and blue (value is 255 so these colors are fully set 1111 1111)
If I draw this bitmap in MS Paint or some other program I'll get the same data as it is stored with my C++ program
My program's bitmap however can't be displayed correctly
So has anybody experienced that problem or has anybody a solution for it?
Would be nice if you reply
|
|
|
|
|
well, another crazy thing is that sometimes the picture is displayed correctly
sometimes distorted
|
|
|
|
|
When an image is distorted then the information associated with is wrong! It appears that someone wrote the code regarding bitmaps based on the requirment that they would be 32 bit. The simpilist solution I can think of is to use my class CDibData to read and store your bitmaps or one of the other classes presented at codeproject. Simply changing the depth (BitCount) will not work!
What you seem to be doing is what is call "pock and hope".
INTP
|
|
|
|
|
I have a question concerning the use of a function defined in a Dll file.
I don't know precisely how to call a function defined in a Dll file.
I follow what MSDN specified but it doesn't work for the functions which take arguments. Here is the syntax I use to call the function "USB_WriteFile" defined in my Dll "XtlUsb.dll":
typedef BOOL (CALLBACK* USB_WriteFile)(PVOID,DWORD,LPDWORD,ULONG);
HINSTANCE hDLL;
hDLL = LoadLibrary("XtlUsb.dll");
USB_WriteFile pUSB_WriteFile;
PVOID lpBuffer = 0;
DWORD nNumberOfBytesToWrite = 0;
LPDWORD lpNumberOfBytesWritten = 0;
ULONG Timeout = Timeout;
if (hDLL != NULL)
{
pUSB_WriteFile = (USB_WriteFile)GetProcAddress(hDLL,"USB_WriteFile");
if (!pUSB_WriteFile)
{
FreeLibrary(hDLL);
return FALSE;
}
else
{
BOOL BResult = TRUE;
BResult = pUSB_WriteFile(lpBuffer,nNumberOfBytesToWrite,lpNumberOfBytesWritten,Timeout);
}
}
I have a fatal error coming from Visual C++ when arriving at the line "BResult = pUSB_WriteFile(lpBuffer,nNumberOfBytesToWrite,lpNumberOfBytesWritten,Timeout);"
Do you have any explanations?
Thank's for advance.
|
|
|
|
|
If that's really your code, then you're passing in NULL for the buffer. This may or may not cause you a problem
Steve S
|
|
|
|
|
That doesn't come from that. For example, I use another function which is defined in my Dll. Here is the Code:
typedef BOOL (CALLBACK* USB_ReadFile)(PVOID,DWORD,LPDWORD,ULONG);
USB_ReadFile pUSB_ReadFile;
char chBuffer[66000];
PVOID *lpBuffer = 0;
DWORD nNumberOfBytesToRead = 65536;
LPDWORD lpNumberOfBytesRead = 0;
ULONG Timeout = 5000;
hDLL = LoadLibrary("XtlUsb.dll");
if (hDLL != NULL)
{
pUSB_ReadFile = (USB_ReadFile)GetProcAddress(hDLL,"USB_ReadFile");
if (!pUSB_ReadFile)
{
FreeLibrary(hDLL);
}
else
{
BOOL BResult = TRUE;
BResult = pUSB_ReadFile(chBuffer,nNumberOfBytesToRead,lpNumberOfBytesRead,Timeout);
}
}
and here is the help given in MSDN:
typedef UINT (CALLBACK* LPFNDLLFUNC1)(DWORD,UINT);
.
.
.
HINSTANCE hDLL; // Handle to DLL
LPFNDLLFUNC1 lpfnDllFunc1; // Function pointer
DWORD dwParam1;
UINT uParam2, uReturnVal;
hDLL = LoadLibrary("MyDLL");
if (hDLL != NULL)
{
lpfnDllFunc1 = (LPFNDLLFUNC1)GetProcAddress(hDLL,
"DLLFunc1");
if (!lpfnDllFunc1)
{
// handle the error
FreeLibrary(hDLL);
return SOME_ERROR_CODE;
}
else
{
// call the function
uReturnVal = lpfnDllFunc1(dwParam1, uParam2);
}
}
The fatal error I have comes from when I call the function with its pointer.
|
|
|
|
|
If you're getting a fatal error (exception, I guess) you could try stepping into the function call with the debugger, and then setting a stop on all exceptions, particularly C0000005 (access violation), and C++ exception.
That might help you work out what's happening.
At a guess, I'd say you were using a USB library to perform I/O to some device. Does your process need particular privileges to do this, or does the device driver (HIDSYS?) take care of it all for you.
Steve S
|
|
|
|
|
I have a question concerning the use of a function defined in a Dll file.
I don't know precisely how to call a function defined in a Dll file.
I follow what MSDN specified but it doesn't work for the functions which take arguments. Here is the syntax I use to call the function "USB_WriteFile" defined in my Dll "XtlUsb.dll":
typedef BOOL (CALLBACK* USB_WriteFile)(PVOID,DWORD,LPDWORD,ULONG);
HINSTANCE hDLL;
hDLL = LoadLibrary("XtlUsb.dll");
USB_WriteFile pUSB_WriteFile;
PVOID lpBuffer = 0;
DWORD nNumberOfBytesToWrite = 0;
LPDWORD lpNumberOfBytesWritten = 0;
ULONG Timeout = Timeout;
if (hDLL != NULL)
{
pUSB_WriteFile = (USB_WriteFile)GetProcAddress(hDLL,"USB_WriteFile");
if (!pUSB_WriteFile)
{
FreeLibrary(hDLL);
return FALSE;
}
else
{
BOOL BResult = TRUE;
BResult = pUSB_WriteFile(lpBuffer,nNumberOfBytesToWrite,lpNumberOfBytesWritten,Timeout);
}
}
I have a fatal error coming from Visual C++ when arriving at the line "BResult = pUSB_WriteFile(lpBuffer,nNumberOfBytesToWrite,lpNumberOfBytesWritten,Timeout);"
Do you have any explanations?
Thank's for advance.
|
|
|
|
|
could this Jeab. wrote:
I have a fatal error be a little more precise?
Don't try it, just do it!
|
|
|
|
|
Fatal error is now OK. The function must be defined like this:
typedef BOOL (__cdecl *USB_ReadFile) (PVOID,DWORD,LPDWORD,ULONG);
PVOID lpBuffer;
DWORD nNumberOfBytesToRead = 65536;
LPDWORD lpNumberOfBytesRead = 0;
ULONG Timeout = 5000;
USB_ReadFile pUSB_ReadFile;
hDll = LoadLibrary("XtlUsb.dll");
if (hDll != NULL)
{
pUSB_ReadFile = (USB_ReadFile)GetProcAddress(hDll,"USB_ReadFile");
if (!pUSB_ReadFile)
{
FreeLibrary(hDll);
return FALSE;
}
else
{
BOOL BResult = TRUE;
BResult = pUSB_ReadFile(lpBuffer,nNumberOfBytesToRead,lpNumberOfBytesRead,Timeout);
}
}
|
|
|
|
|
below ,it is a part of program.
BOOL CAboutDlg::OnInitDialog()
{
CDialog::OnInitDialog();
VERIFY(m_editCopy.AutoLoad(IDC_button, this));
TRACE("HELLO");
return TRUE;
}
i insert two bitmaps ,at the same time ,i insert a button whose id is "IDC_BUTTON" and name "copy" .the two bitmap's id are "COPYU" and "COPYD".
I want to connect the copy button withe the two bitmaps by the function of "AutoLoad()",but when i run it,nothing error ,but why can not i get the
expected result?
|
|
|
|
|
I try to find where is error and make small test program like your but it is working well. You must check your code and I do not know did you write resource simbol IDC_BUTTON or "IDC_BUTTON". Second is wrong in your case.
Regards,
|
|
|
|
|
I'm looking for a hash table that maps strings to strings. I want to use this in a hooking procedure. The classical mfc classes don't work because pointers are a big nono for global hooking (dll mapped at different addresses for different processes). I tried and it sometimes works but most of the time not.
Basically I need a hooking class that uses static allocated tables. It should also know to manage memory itself (no malloc or free allowed) internally. Anyone know of such a class before I reinvent the wheel ?
|
|
|
|
|
Hi...
It's my first time using vectors and I'm having problem using the 'begin' method. I did as follows...
vector ** a = new vector *[size];
...
vector<int>::iterator iter = a[u][v].begin();
a[u][v].insert(iter,lab);
...
I get unhandled exception error upon reading the iterator statement.
Pls help me allocate a value at the beginning of the 2d array...
Thank you.
Rgrds.
|
|
|
|
|
Here is a class that shows how you can make a std::vector of std::vectors. It is heretic from the pure techings of the OOP-priests in that it inherits from a class (std::vector) that has no virtual destructor. Lint is crying in horror and I had to insert a switch.
But it works for me all the time. Also, a earlier version of a book by Alexandrescu also showed something like this.
/* matrix as vector of vectors*/
template<class T>
class Matrix : public std::vector<std::vector<T> > //lint -save -e1509
{
protected:
size_type rows,
columns;
public:
explicit Matrix(size_type r = 0, size_type c = 0)
: std::vector<std::vector<T> >(r, std::vector<T>(c)),
rows(r), columns(c)
{}
/* Thus, the Matrix class inherits from the std::vector class,
with the data type of the vector elements now being described
by a std::vector<T> template. With this, the matrix is a
nested container that exploits the combination of templates
with inheritance. The constructor initializes the implicit
subobject of the base class type (std::vector<std::vector<T> >)
with the correct size x. Exactly as with the standard vector
container, the second parameter of the constructor specifies
with which value each vector element is to be initialized.
Here, the value is nothing else but a vector of type
std::vector<T> and length y.*/
size_type Rows() const {return rows; }
size_type Columns() const {return columns; }
void init(const T& Value)
{
for (size_type i = 0; i < rows; ++i)
for (size_type j = 0; j < columns; ++j)
operator[](i)[j] = Value; // i.e. (*this)[i][j]
}
/* The index operator operator[]() is inherited from
std::vector. Applied to i, it supplies a reference to the ith
element of the (base class subobject) vector. This element is
itself a vector of type std::vector<T>. It is again applied
to the index operator, this time with the value j, which
returns a reference to an object of type T, which is then
assigned the value. */
// here, mathematical operators could follow ...
}; // class Matrix
//lint -restore
<hr size=1 /hr><small>"We trained hard, but it seemed that every time we were beginning to form up into teams we would be reorganised. I was to learn later in life that we tend to meet any new situation by reorganising: and a wonderful method it can be for creating the illusion of progress, while producing confusion, inefficiency and demoralisation."
-- Caius Petronius, Roman Consul, 66 A.D.</small>
|
|
|
|
|
<i>template<class T>
class Matrix : public std::vector<std::vector<T>> /* ... */ </i>
Not able to compile the code with Visual C++ .NET 2002.
<b>Maxwell Chen</b>
|
|
|
|
|
[Edited to show the templates corrcetly]
This, copied into a Win32-console-project, compiles with VC2003. Also, I know that VC6 is able to compile the class and produce running code from it.
Hope this helps!
------------------------------------------
#include "stdafx.h"
#include <vector>
/* matrix as vector of vectors*/
template<class T>
class Matrix : public std::vector<std::vector<T> > //lint -save -e1509
{
protected:
size_type rows,
columns;
public:
explicit Matrix(size_type r = 0, size_type c = 0)
: std::vector<std::vector<T> >(r, std::vector<T>(c)),
rows(r), columns(c)
{}
/* Thus, the Matrix class inherits from the std::vector class,
with the data type of the vector elements now being described
by a std::vector<T> template. With this, the matrix is a
nested container that exploits the combination of templates
with inheritance. The constructor initializes the implicit
subobject of the base class type (std::vector<std::vector<T> >)
with the correct size x. Exactly as with the standard vector
container, the second parameter of the constructor specifies
with which value each vector element is to be initialized.
Here, the value is nothing else but a vector of type
std::vector<T> and length y.*/
size_type Rows() const {return rows; }
size_type Columns() const {return columns; }
void init(const T& Value)
{
for (size_type i = 0; i < rows; ++i)
for (size_type j = 0; j < columns; ++j)
operator[](i)[j] = Value; // i.e. (*this)[i][j]
}
/* The index operator operator[]() is inherited from
std::vector. Applied to i, it supplies a reference to the ith
element of the (base class subobject) vector. This element is
itself a vector of type std::vector<T>. It is again applied
to the index operator, this time with the value j, which
returns a reference to an object of type T, which is then
assigned the value. */
// here, mathematical operators could follow ...
}; // class Matrix
//lint -restore
int _tmain(int argc, _TCHAR* argv[])
{
Matrix<double> ma(12, 12);
ma.init( 12.0);
return 0;
}
re beginning to form up into teams we would be reorganised. I was to learn later in life that we tend to meet any new situation by reorganising: and a wonderful method it can be for creating the illusion of progress, while producing confusion, inefficiency and demoralisation."
-- Caius Petronius, Roman Consul, 66 A.D.</small>
|
|
|
|
|
Finally I found where the problem is. (Still with VC++ .NET 2002.)
1) If I write the code this way, it definitely does not compile:
class Matrix : public std::vector<std::vector<T>>
2) If this way, it compiles very well (note the space):
class Matrix : public std::vector<std::vector<T> >
Maxwell Chen
|
|
|
|
|
Yes. Poor compiler: It thought you had asked for the shift-right operator.
One of these errors I always tend to overlook.
"We trained hard, but it seemed that every time we were beginning to form up into teams we would be reorganised. I was to learn later in life that we tend to meet any new situation by reorganising: and a wonderful method it can be for creating the illusion of progress, while producing confusion, inefficiency and demoralisation."
-- Caius Petronius, Roman Consul, 66 A.D.
|
|
|
|
|
You have successfully created an array of pointers to vectors, but not the vectors being pointed at:
vector **a = new vector*[size];
for (int index = 0 ; index < size ; index++)
{
a[index] = new vector;
}
...
don't forget to delete them properly when you have finished with them.
for (index = 0 ; index < size ; index++)
{
delete a[index];
}
delete []a;
Roger Allen - Sonork 100.10016
<small><b>Strong Sad:
</b><i>Clever I am? Next to no one.
Undiscovered and soggy.
Look up. Look down. They're around.
Probably laughing. Still, bright, watery.
Listed among the top. Ten.
Nine. Late night. Early morn.
Early mourn. Now I sleep. </i></small>
|
|
|
|
|
(in visual studio .net)
I'm a programmer mostly coming from the academic end of things (UNIX, gcc, etc.) and for the life of me cannot get variable types/functions from this dll. It's a development package for eeg analysis software that's supposed to allow me to read their specialized file format in c++ programs. Here's the link to the development kit:
http://www.axon.com/pub/utility/axonfsp/windows/
and I'm interested in using the axabffio32.dll functions and what (esp. things like ABF_ReadOpen and Abffileheader).
I've tried linking in the dir of the dll, copying the dll to the project dir, setting everything to release and adding the dll as a resource (as well as the #include of the dll)...what am I doing wrong???
here's the code:
void main( int argc, char **argv )
{
ABFFileHeader FH;
ABF_Initialize();
ABFH_Initialize(&FH);
Acquisition( argv[1], &FH );
ABF_Cleanup();
}
and here's the error I most often get:
c:\Documents and Settings\administrator\My Documents\Visual Studio Projects\abfDLL\abfDLL.cpp(16) : error C2065: 'ABFFileHeader' : undeclared identifier
c:\Documents and Settings\administrator\My Documents\Visual Studio Projects\abfDLL\abfDLL.cpp(16) : error C2146: syntax error : missing ';' before identifier 'FH'
c:\Documents and Settings\administrator\My Documents\Visual Studio Projects\abfDLL\abfDLL.cpp(16) : error C2065: 'FH' : undeclared identifier
c:\Documents and Settings\administrator\My Documents\Visual Studio Projects\abfDLL\abfDLL.cpp(18) : error C3861: 'ABF_Initialize': identifier not found, even with argument-dependent lookup
c:\Documents and Settings\administrator\My Documents\Visual Studio Projects\abfDLL\abfDLL.cpp(19) : error C3861: 'ABFH_Initialize': identifier not found, even with argument-dependent lookup
|
|
|
|
|