|
Assuming the DLL and the scripting language need no further interaction
after the call...
DLLFunctionCalledByScriptingLanguage
{
createthread(ThreadProc)
return
}
ThreadProc
{
allocate some memory
do some stuff
free memory
return
}
That's the same as yours except the memory operations are all
in the thread procedure and the function doesn't wait for the thread
to end before returning control to the caller, thus making it truly
multithreaded. Make sense?
How often and how many times would this be called by the scripting language?
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hello,
i am working on a 3D project. some where in my program i need to draw a plan that is perpendicular to a vector MB. for doing this i need to know the (x,y,z) of each voxel in this plan (a portion of the plan or window).
for this i need to make a marix that transform a well known vector MA (for exemple parallel to X axis) to a known vector MB of the same length. why ? because I will calculate the (x,y,z) of the plan perpendicular to X axis (witch is easy to calculate) and then multiplay by the matrix to obtain the (x,y,z) in the new plan (perpendicular to MB)
So i need a rotation matrix (because of the same origin M of the two vectors). I think i can do only two rotations (on Y and Z axis) to obtain the new vector MB.
think you
|
|
|
|
|
See, for instance [^].
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]
|
|
|
|
|
|
In the Matrix literature I only find rotation about x, y or z axis or even rotation about a vector. but i can t find a matrix to have a vector from an other.
I don t know if i can consider the multiplication of two matrix (one alpha rotation about y and beta rotation about z) and try to find alpha and beta.
excuse me but i am not good at maths
|
|
|
|
|
Well, you may obtain a vector from another (having the same lenght) simply translating + rotating it.
Off course you need to find the translation and rotation parameters.
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]
|
|
|
|
|
I have found the solution (no translation is needed because of the same origine)
To find a matrix that transform a vector MA to a vector MB you can try this:
1) If MA and MB are not unit length, normalize it.
2) Calculate the dot product of MA and MB, this will give the cosinus of the angle between MA and MB. To get the angle, take the arccos of the result.
3) Calculate the cross product of MA and MB, this will give a vector for the axe of rotation.
4) Now we have an angle and a vector. Then you can use the Rodrigues formula to calculate a rotation matrix to rotate MA to MB.
|
|
|
|
|
Balanced here.
Many are stubborn in pursuit of the path they have chosen, few in pursuit of the goal - Friedrich Nietzsche
.·´¯`·->Rajesh<-·´¯`·.
[Microsoft MVP - Visual C++]
|
|
|
|
|
Thank you, pal.
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]
|
|
|
|
|
I'm not sure how I should go about approaching this problem, but is there any way to create a bitmap by loading a "file in memory"?
Let me explain. So, I initially have an encrypted .bmp on disk, that I load into a std::ifstream, decrypt, and dump back out to a char*. The char array essentially contains the entire file, character by character, meaning that if I were to dump it to an std::ofstream, I would get the decrypted version of the file I loaded into the std::ifstream (which would also happen to be a bitmap that I can view with any picture viewer). The problem is, I want to generate a bitmap from this "file in memory" stored as a char* and all the functions I know of either require a file name, or require loading it from an executable resource. The end result should be a Win32 BITMAP object. Is there any way of doing what I'd like to do?
Thanks.
|
|
|
|
|
|
This might work. I'm not inherently familiar with some of the parameters that have to be passed in, but I think I'll manage (and post back if I have issues).
Thanks again!
|
|
|
|
|
Cyrilix wrote: I'm not inherently familiar with some of the parameters that have to be passed in
Here's a clue...
The first structure is a BITMAPFILEHEADER[^].
You'll find an offset to the pixel data there.
Following that is a BITMAPINFO[^] structure,
within which you'll find a BITMAPINFOHEADER[^]
structure.
Bitmap Storage[^]
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I've been looking around for code examples and trying to figure out the concepts in my head, and somehow, I think I'm using the wrong function (CreateDIBitmap) for what I want to do, since I have to pass in a device context. From what I've read, the device context is like a drawing surface, but I have no need for a drawing surface, since I don't actually plan on drawing the bitmap to a window. All I want to do is get a BITMAP which can then have its pixels altered (which in my mind, would mean setting bits contained in my BITMAP.bmBits structure to different values). What do you guys think? Am I just really confused or onto something?
To clarify, my plan was the following:
-Load encrypted file and store it as an encrypted memory stream
-Decrypt memory stream and convert to BITMAP type
-Do image processing on BITMAP type
-Convert BITMAP back to a decrypted memory stream and encrypt
-Save encrypted memory stream to file
|
|
|
|
|
If you're going to manipulate the pixel data directly, then
you can use a DIBSection ("a DIB that applications can
write to directly").
CreateDIBSection()[^]
The passed DC can be NULL for DIB_RGB_COLORS bitmaps.
If you don't use a file mapping to create the DIBSection, you'll need
to copy the pixel bits from your array to the allocated pixel bits pointer.
The number of bytes to copy can be determined something like the following
(psudocode):
LONG NumberOfPixelBytes;
if (0 != BITMAPINFOHEADER.biSizeImage)
NumberOfPixelBytes = BITMAPINFOHEADER.biSizeImage;
else
NumberOfPixelBytes = (((BITMAPINFOHEADER.biWidth * (long)BITMAPINFOHEADER.biBitCount + 31L) & (~31L)) / 8L) * BITMAPINFOHEADER.biHeight;
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hi Mark,
I've got a good idea of how to do this when it comes to initially loading the Bitmap. The only other issue I have is saving the Bitmap back. My impression is that from an HBITMAP that is returned from CreateDIBSection(), we can get a BITMAP by calling GetObject() in such a manner:
HBITMAP hBmp = CreateDIBSection(...);
BITMAP bmp;
GetObject(hBmp, sizeof(bmp), &bmp);
But, the BITMAP object itself does not seem to have enough information to recreate the BITMAP file. For instance, from the MSDN documentation, it states that BITMAP has the following members:
LONG bmType;
LONG bmWidth;
LONG bmHeight;
LONG bmWidthBytes;
WORD bmPlanes;
WORD bmBitsPixel;
LPVOID bmBits;
The BITMAP file specification, on the other hand, has (as your link described):
BITMAPFILEHEADER:
WORD bfType;
DWORD bfSize;
WORD bfReserved1;
WORD bfReserved2;
DWORD bfOffBits;
BITMAPINFO:
RGBQUAD bmiColors[1];
BITMAPINFOHEADER (inside BITMAPINFO):
DWORD biSize;
LONG biWidth;
LONG biHeight;
WORD biPlanes;
WORD biBitCount;
DWORD biCompression;
DWORD biSizeImage;
LONG biXPelsPerMeter;
LONG biYPelsPerMeter;
DWORD biClrUsed;
DWORD biClrImportant;
RGBQUAD array: data that has to do with palettes
Color-index array: the raw image data itself
If you compare the two lists, it would seem like BITMAP contains enough information to recreate most of the variables in BITMAPINFOHEADER as well as the info needed for the color-index array, but what about the rest of the info? It would seem like if I'm trying to convert it back to a char array, I would have to do some fancy extrapolation myself, in addition to saving some of the info that I had when I loaded the image. I will have another careful look at all of the BITMAP related functions to see if I've missed something, but at the moment, I'm sort of stuck at this point.
Also, if I haven't mentioned it to you yet, your advice so far been much appreciated.
|
|
|
|
|
Cyrilix wrote: from an HBITMAP that is returned from CreateDIBSection(), we can get a BITMAP by calling GetObject() in such a manner:
No need to make it that complicated - just keep the original headers!
All the info you need is there. You're only changing the pixels, right?
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Well, in a sense, that's true, but I'd also like to handle the case where I've gotten a BITMAP from somewhere else (i.e., just been passed a BITMAP from another function), and I'm asked to save it. Is that not possible to implement easily?
|
|
|
|
|
Cyrilix wrote: Is that not possible to implement easily?
BMP bitmaps are the easiest format to save. The Bitmap Storage[^]
shows the layout of the file.
Another option:
If you're not into writing the code yourself, and you can use an ATL
class, the CImage class[^] is a nice lightweight
wrapper around a DIBSecion bitmap and will load and save in other
formats beyond BMP. The member functions make it easy to do all
the things you've discussed so far.
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
get this error for 133 times:
CxImage.lib(ximajpg.obj) : error LNK2019:unresolved external symbol "_jpeg_finish_decompress" in Function ""public: bool __thiscall CxImageJPG::Decode(class CxFile *)
"(?Decode@CxImageJPG@@QAE_NPAVCxFile@@@Z)".
followed by fatal error LNK1120
Please help, i have tried to search in google but no way .
|
|
|
|
|
Looks like you missed to link some required library. Have you read about all CxImage requirements?
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]
|
|
|
|
|
Did you import a lib file to your project?
|
|
|
|
|
I do have a wicked anomaly regarding an "out of memory" situation which behaves differently in two of my applications.
Application 1, let it be called "tool", is an inhouse tool, MFC based with full MFC GUI and stuff.
Application 2, let it be called "client", is a multiplayer game client, using MFC but only for the network socket, the whole GUI being custom on top of OpenGL/DirectX.
Both applications are made with Visual C++ 2003.NET / v7.1.6030 unter WindowsXP. Only the "Release" mode is currently used.
For exception handling of win32 exceptions both have the following project properties set...
Project Properties -> C/C++ -> Code Generation -> Enable C++ Exceptions = No
Project Properties -> C/C++ -> Command Line = /EHa
...plus...
_set_se_translator(myfunction)
...is used (based on the information I found here[^]).
But the wicked thing comes with memory allocation and the throwing vs. not-throwing of a std::bad_alloc exception. If I put the following code into both applications...
Byte* pData = NULL;
try {
int Amount = 0;
--Amount;
pData = new Byte[Amount];
}
catch (std::bad_alloc& E) {
}
...they behave differently:
The "tool" behaves as I would expect and a std::bad_alloc exception is thrown, catched and my own error handling does the rest.
But in the "client" a Windows message box comes up, simply telling me "Out of memory." with a black exclamation mark in a yellow triangle plus an OK button and if I press the OK button the application continues to run - which actually gives me a big "WTF?" moment. One way or the other that behaviour is neither intended nor appreciated.
My best guess is that it depends on the compiler settings but I wasn't able yet to find any meaningful differences. I already experimented with optimization levels but couldn't change the application's behaviour doing so. Could anybody give me a hint on what the problem might be?
Thanks,
T.T.H.
|
|
|
|
|
Answering myself:
Both applications seem to use different implementations of the new operator - despite both using the MFC:
Application 1 uses the one from the CRT and throws a std::bad_alloc exception.
Application 2 uses the one from the MFC and throws a CMemoryException*.
According to "Binglong's Blog" (link see below) the actual choice which new operator will be used depends on (quote) "the operator new comes from the library the linker sees first". Ugh. What a mess. Unfortunately I was not able to define myself what "the linker sees first". If somebody has a handy hint, go ahead, will be very apprectiated!
In addition to that there seems to appear some "Microsoftic Magical Trick": in case a CException is thrown ""somebody"" checks whether it will be catched - if yes, it the exception will be thrown, if not, the application will not simply crash but a message box will be displayed and the application can run on. Please note that this is an assumption based on my observation and to be honest I don't consider it helpful to wastespend more time on examining that behaviour further.
Helpful links:
Binglong's space: Operator new, STL memory allocator, and MSVC[^]
Visual C++ 6.0: Don't Let Memory Allocation Failures Crash Your Legacy STL Application[^]
Visual C++ exception handling[^]
|
|
|
|
|
I know! I've posted this once before, but I didn't get my answer. Sorry! I'm quite new and I know this may seems funny; But the problem is:
I wanna send a file to a given eMail address "without displaying any dialog box from STRANGER applications like outlook express or anything".
Frankly speaking, I don't wanna fall into reading boring APIs So could you please direct me to a
free source or an utility or somethig ...
Thank you masters!
|
|
|
|