Thanks Superman, Exactly what I wanted. Whenever I search msdn I seem to find it have to get relevant results. my only realy experience it with .NET/JAVA and therefore when looking I'm a little non-plussed when it comes to C++/MFC and what is possible. Great
Ylno
Posts
-
VC++6.0 Interproc Communication -
VC++6.0 Interproc CommunicationIn .NET we have the System.IO namespace providing convenient classes for Sockects and Pipes which ay be used for interprocess communication. How can one implement this in oldskool VC6? My requirements are as follows. I am writing a plugin for some legacy software for which there is a SDK which I can only get to compile with VC++6.0 compiler. I want to interface this code with both .NET and JAVA. I was thinking of implementing either a Socket server or Namedpipe in C# to act a a bridge between the VC6 code and .NET/JAVA. Requests from VC6 would be in the form of byte[] arrays and the C# bridge would interpret these requests, route them and eventually reply to the VC6 code which is awaiting a response. In summary I would like examples of the following in VC++6: - Use of threads - Socket/Pipes (or any other interproc comms method) - Invoking a process (other than a shell call to an executable) BTW non-MFC is required Any suggestions would be great. Best, Y
-
Bitmap.Lockbytes AccessViolationHi Luc, You spotted the mistake! Was just making sure you were paying attention. There was a factor of 3 missing from my display-array [width*height*3] and the increment on the loop is 3 not 1 (loop+=3 not loop++). I'm filling the pixels thrice to have RGB values each the same. This gives me a greyscale and also some flexibility in that I can drop values from one of the channels and achieve colour a colour overlay effect with the same image. With the code above using a 1000x1000 array input array ( i.e. a (1000x1000)x3 display array) I get 19ms total runtime for creating the display array, making the pixel assignments and displaying in a picture box! Nice. Cheers for your help.
-
Bitmap.Lockbytes AccessViolationThanks again for getting back to me on this subject.
Luc Pattyn wrote:
I don't see it!
sorry, I simply meant my discussion about having pixels stored in a double[,] array but not really caring with what pixel-depth the bitmap is since is it is only for display purposes not calculation. 5. I guess "see above" 6. Same here. Other than GDI+ not fully supporting 16bpp. There is very little on the net regarding using 16bpp greyscale Bitmaps and what there is is old and contradictory. 7. I went with your suggestion here however I couldn't get things to work using PixelFormat.Format16bppGrayScale. Instead I went with 24bppRGB instead. For the benefit of others see code below. 8. yes, I was aware of this (once) but could you remind me of the benefits? My reasons for using 2D are: 8.1 - the dimensions are carried with the data in array.GetLength(int dimension). The vector approach requires lacks this. 8.2 - the array is analogous to the raster image and therefore conceptually simpler. 8.3 - this is my first 'real' stab at writing an heavy image processing application. Aren't the 2D and 1D arrays arranged the same in memory? Thanks again for your help. Pushed me towards a solution. :) and finally here's what I came up with:
// DEFINE AN IMAGE ALONG WITH ITS DIMENSIONS // 24bpp -> three channels each of one byte depth int width = 1000; int height = 1000; byte\[\] pixelVector = new byte\[width \* height \* 3\]; // FILL THE PIXELS WITH SOMEDATA AVOIDING OVERFLOW for (int loop = 0; loop < (width \* height ); loop+=3) { pixelVector\[loop\] = (byte)((loop \* 256) / (width \* height )); pixelVector\[loop + 1\] = (byte)((loop \* 256) / (width \* height )); pixelVector\[loop + 2\] = (byte)((loop \* 256) / (width \* height )); } // CREATE THE DESTINATION BITMAP WITH THE REQUIRED PIXEL-DEPTH Bitmap bmp = new Bitmap(width, height, PixelFormat.Format24bppRgb); // LOCK IT'S DATA FOR EXCLUSIVE ACCESS BitmapData bmpData = bmp.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.WriteOnly, bmp.PixelFormat); unsafe { // GET THE ADDRESS OF THE FIRST PIXEL IN MEMORY byte\* row = (byte\*)bmpData.Scan0; // LOOP THROUGH THE PIX
-
Bitmap.Lockbytes AccessViolationHi Luc, 1) in this test 1000x1000 but in practice 1024x1024 or 2048x2048 2) using bmp.PixelFormat (see below) 3) the line with
row[i * PixelDepth] = pixVal;
within the inner loop throws. background: I'm parsing grayscale pixel data from an obscure image format used in electron-microscopy. Along with the pixel values I get the Width, Height and PixelDepth. The actual image has been acquired on expensive ccd equipment therefore pixels can be quite deep. I want to be able to display an array of greyscale pixel values (double[,] pixelValues) within a picture box. For this I see no other way than creating a Bitmap/Image in memory and displaying this. It appears .NET does not support deep greyscale therefore I thought for the purposes of display only I could rescale the pixelArray from double[,] to byte[,] and assign each of the RGB channels for a given pixel to the byte value from the temporary byte[,] array. Towards this end my code creates a byte-buffer vector in which I encode a Bitmap. First I write the header in which I define the pixelDepth to be 32. Previously I thought I could use ARGB 32bbp format and push the byte pixelValue in R, G and B a constant in the A channel. This worked:
....... code to write the bitmap header here ........ for (int j = Height - 1; j >= 0; j--) { for (int i = 0; i < Width; i++) { pixVal = (byte)(PixelScaleFactor * (_internalPixelArray[i, j] - PixelOffset)); buffer.writeByte(pixVal); buffer.writeByte(pixVal); buffer.writeByte(pixVal); buffer.writeByte(0); // the alpha channel. } }
I then use the bitmap encoded byte[] buffer to create a memory stream from which I create an image by:Image.FromStream(new System.IO.MemoryStream(imageData))
This works but takes 200ms to encode and display an image. To make things quicker I thought I might be able to by encoding a buffer with a bitmap header as above and not assign the pixel values immediately but instead create a Bitmap using the memory stream method which results in an images with all pixels as zero. Then once I have the Bitmap object used Lockbits to set the pixels. I got to point and got an AccessViolation. I thought my buffer might not be long enough so I backed up a bit and started testing with the code I posted. i.e. create a simple bitmap using Bitmap(width, height) constructor and specify the pixelDepth with the Lockbits method. This way I thought I would be allocat
-
Bitmap.Lockbytes AccessViolationHi I'm trying to push a double[,] array of pixel values from a greyscale buffer into a bitmap using lockbit using:
Bitmap bmp;
byte pixVal;
unsafe{bmp = new Bitmap(Width,Height);
BitmapData bmpData = bmp.LockBits(
new Rectangle(0, 0, Width, Height),
ImageLockMode.ReadWrite,
PixelFormat.Format24bppRgb);
byte* row;
for (int j = 0; j < Height; j++){
row = (byte*)bmpData.Scan0 + (j * bmpData.Stride);
for (int i = 0; i < Width; i++){
pixVal = (byte)(PixelScaleFactor *
_internalPixelArray[i, j] - PixelOffset));row\[i \* PixelDepth\] = pixVal; row\[i \* PixelDepth + 1\] = pixVal; row\[i \* PixelDepth + 2\] = pixVal; }
}
bmp.UnlockBits(bmpData);}
in which _internalPixelArray is a 1000x1000 array of doubles. The scale factor and pixelOffset have been calculated correctly. When run I get an AccessViolationException when j = 991 and i = 918. Could there be a reason for this? Cheers,
-
persistent pointer/memory allocationHello All, A little question about memory allocation. Yes, nos and look heres greatly accepted... I'm not sure how to word the question so I'll say what I want to do: I want to, from one program, allocate a block of memory noting its memory address/pointer. When this program finished I do not want to free up this memory location but rather be able to access it from a second program and be guarenteed of what I'll find there. Basically I want to be able to take this address and, in a completly seperate program, access this memory and then deacllocate/free it up. Is this possible? Thanks...
-
Threads and Memory AllocationMark, I know i've created a useless piece of code. Please give me a hint about how to make this piece of code fit what i'm trying to do... How do I make sure the heap is freed up and let this function return so that the scripting language can continue its excecution. En espérant
-
Threads and Memory AllocationOk, I've implemented a heap clean up at the end of the code. Problem now is that when i call this function it waits untill the thread finishes until returning. Can anyone see a way of perhaps having the code below return the address of the Thread and the pPulseData and have another code clean the memory for these two addresses. Thanks
float LPTPulseThreaded(float aPortAddress, float aValue1, float aValue2, float aTime1, float aTime2, float aTimes, float aControlAddress, float aOffOnValue){
PDATA pPulseData[1]; // Pointer to the funtion
DWORD dwThread[1];
HANDLE hThread[1];
// Allocate memory for thread
pPulseData[0] = (PDATA)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(DATA));
// Populate the data struct
pPulseData[0]->PortAddress = aPortAddress;
pPulseData[0]->Value1 = aValue1;
pPulseData[0]->Value2 = aValue2;
pPulseData[0]->Time1 = aTime1;
pPulseData[0]->Time2 = aTime2;
pPulseData[0]->Times = aTimes;
pPulseData[0]->ControlAddress = aControlAddress;
pPulseData[0]->OffOnValue = aOffOnValue;
// Create the thread
hThread[0] = CreateThread(NULL, 0,PulseThread, pPulseData, 0, &dwThread[0]);
// Check to see if thread creation failed
if(hThread[0] == NULL){return 1;}
// Wait untill all threads have finished
WaitForMultipleObjects(1, hThread, TRUE, 10000);
// Free up the memory
HeapFree(GetProcessHeap(), 0, pPulseData[0]);
pPulseData[0] = NULL;return 0;
}
-
Threads and Memory AllocationHi Mark, I will put a heap free call in. Thanks.
-
Threads and Memory AllocationHi, Sorry. I was just writing "thread finished" as a test in the program. I should have written "thread called" or something similar. I just wanted to see if the thread would work independantly of the main program/thread. You say that you don't see anything wrong with the code. Do that mean that when a thread finished that it reallocates any memory from on the heap as free to use memory? Also you said << Why HeapAlloc and not "new"? >>. Why do you mean? thanks for your reply, Y
-
Threads and Memory AllocationHello, This is my first attempt at using threads so go easy. Could some one look at the code below and tell me if I'm going to run into trouble if I keep calling this function i.e. loss of memory. The reason why I'm trying to use a Thread is this: we are writing .dll files to add functionality to a scripting language which is used in a software. The problem is that when a c++ function is called from a .dll file from within this scripting language the next line of code (in the script) doesn't get called until the .dll's function has returned. I was thinking that I could use a thread to get around this problem. Does this make sense? or is there another way of doing it? Thanks
#include #include using namespace std;
typedef struct PulseData {
int iData1;
int iData2;
} DATA, *PDATA;DWORD WINAPI TestFunction(LPVOID lpParam){
PDATA pPassedData = (PDATA)lpParam;
Sleep(1);
cout << pPassedData->iData1 << endl;
cout << pPassedData->iData2 << endl;
Sleep(1);
return 0;
}int main(){
PDATA pPulseData[1];
DWORD dwThread[1];
HANDLE hThread[1];
// Allocate memory for thread
pPulseData[0] = (PDATA)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(DATA));pPulseData\[0\]->iData1 = 100; pPulseData\[0\]->iData2 = 200; cout << "creating thread" << endl; hThread\[0\] = CreateThread(NULL, 0,TestFunction, pPulseData, 0, &dwThread\[0\]); cout << "thread finished" << endl; system("PAUSE"); return 0;
}
p.s. the includes are: #include #include I don't know why they don't show up in the code
-
Getting VC6 code to compile on VS2008Hello All, What's the best way for someone, who knows just enough of C++ to know what to search for on the internet and piece programs together that way, to get VC6 programs to compile under VS2008. It there a way to get the compiler to ignore pieces of code that do not comply with new standards? or is there some software that will rewrite the old code so that it will comply with newer standards? or is there another way of doing this that doesn't require me to fully learn the historical development of C++ under windows? Thanks, G
-
Program Like Spy++ But Not Spy++Hi Thanks for the suggestion. Only problem with that app is that it doesn't show the parent-child relationships. I want this functionality becaue once i found when using spy++ with internet explorer that it wouldnt highlight all the children down to the lowest level and i was missing a step in my enumeration process.......
-
Needed: Code or Component to do Bulk Emails (Persistent SMTP Connections)Look in to using VBA to control Outlook. If you go over to mrexcel.com you'll find some code(search the message boards) that will control outlook from Excel. That way you just set up your spread sheets and have the code loop through the lists sending email as it goes.
-
Program Like Spy++ But Not Spy++Hello, I used to have a program which like Spy++ allowed you to drag the coursor over a windows and it would display the window's handle and other information. Unlike Spy++ it also showed the parent-child relationship of forms and their components. Does anyone know what program this is or where I can find something similar? Thanks
-
Getting TopMost MDIChildHi, I have a MDI application and I want to get the child form which is currently in focus/on top/being used. I've tried using logic like this to loop through all the MDIChildren:
array^ children = this->MdiChildren; for each (System::Windows::Forms::Form^ form in children){ if(form->TopMost){ System::Windows::Forms::MessageBox::Show(form->Text->ToString()); } }
but it doesn't work. -
follow the library(.dll) calls of an application ... [modified]Hello, i'm using a piece of software in work which provides a scripting interface however there is little reference material regarding the scripting language and a lot of the software's functionallity cannot be accesed through the scripting language. It is however possible for me to complile dll plugins and use their methods from the scripting langauge. Therefore I'm thinking of 'hacking-out' functionality from the application. I would like to know if it is possible to trace the calls made by the application to the .dlls which hold all the functionality. i'm imagining a situation where I'm able to 1 - start the application 2 - Attach some kind of debugger-thing to it 3 - press a button in the application 4 - trace the method calls made by the application and follow the data flow I guess if this is possible it won't be as easy as outlined above but I'd just like to know if there is anything that would help me along in my quest. For Example: Does anyone have a freeware .dll inspector (does VS have one?) that will show all exported functions? Thanks EDIT: This looks like a good free .dll viewer: http://www.download3000.com/download-DLL_Export_Viewer-count-reg-8884.html[^]
modified on Tuesday, March 11, 2008 7:11 PM
-
Compiles with VC6. Is this still available?Thanks very much for the help. I'll take a look at those links. Thanks
-
Compiles with VC6. Is this still available?Hi CPallini, Yes I have sorted all the previous errors with the suggestions. I wanted to show them in case there was something i could do with the compile options to get rid of these errors. (I thought I could ask the compiler to be less strict. Since i got the same thing to compile first time with VC6). Here's where i'm at now. Linker errors: (the project was set up so that the linker has the path of the library) Do you know what the weird combination of symbols mean? such as:
(??0bad_cast@std@@QAE@PBD@Z)
1>Linking... 1>LIBCMTD.lib(stdexcpt.obj) : error LNK2005: "public: __thiscall std::bad_cast::bad_cast(char const *)" (??0bad_cast@std@@QAE@PBD@Z) already defined in DMPlugInBasic-Dbg.lib(ImageUtility.obj) 1>LIBCMTD.lib(stdexcpt.obj) : error LNK2005: "public: __thiscall std::bad_cast::bad_cast(class std::bad_cast const &)" (??0bad_cast@std@@QAE@ABV01@@Z) already defined in DMPlugInBasic-Dbg.lib(ImageUtility.obj) 1>LIBCMTD.lib(stdexcpt.obj) : error LNK2005: "public: virtual __thiscall std::bad_cast::~bad_cast(void)" (??1bad_cast@std@@UAE@XZ) already defined in DMPlugInBasic-Dbg.lib(ImageUtility.obj) 1> Creating library .\Debug/LibraryExample.lib and object .\Debug/LibraryExample.exp 1>LibraryExample.obj : error LNK2019: unresolved external symbol "void __cdecl Gatan::PlugIn::DMScript_HandleException(struct Gatan::PlugIn::DM_Env *,class std::exception const &)" (?DMScript_HandleException@PlugIn@Gatan@@YAXPAUDM_Env@12@ABVexception@std@@@Z) referenced in function __catch$?PlugIn_Start@@YAXXZ$0 1>DMPlugInBasic-Dbg.lib(PlugInUtility.obj) : error LNK2001: unresolved external symbol "private: static class std::locale::_Locimp * std::locale::_Locimp::_Global" (?_Global@_Locimp@locale@std@@0PAV123@A) 1>DMPlugInBasic-Dbg.lib(PlugInUtility.obj) : error LNK2019: unresolved external symbol "protected: void __thiscall std::ios_base::_Addstd(void)" (?_Addstd@ios_base@std@@IAEXXZ) referenced in function "protected: void __thiscall std::basic_ios >::init(class std::basic_streambuf > *,bool)" (?init@?$basic_ios@DU?$char_traits@D@std@@@std@@IAEXPAV?$basic_streambuf@DU?$char_traits@D@std@@@2@_N@Z) 1>DMPlugInBasic-Dbg.lib(PlugInUtility.obj) : error LNK2001: unresolved external symbol "__int64 const std::_Fpz" (?_Fpz@std@@3_JB) 1>DMPlugInBasic-Dbg.lib(PlugInUtility.obj) : error LNK2019: unresolved external symbol "void __cdecl std::_Xlen(void)" (?_Xlen@std@@YAXXZ) referenced in f