Quantcast
Channel: Visual C forum
Viewing all 15302 articles
Browse latest View live

Behavior of MessageBox API on Win7 X64 system with different locales

$
0
0

Hello,

To confirm the behavior of the windows MessageBox API we wrote a simple program and when run on English and French Win7 x64 system the locale of the "OK" button remains to be english and on spanish win7 system it becomes spanish. Please see the attached snapshots for more details.

I would like to understand this difference in behaviour on windows 7 x64 system with Spanish locale.

I will attach the screen shots captured.

/aubhp



Dynamic replacemnt of a Ribbon toolbar button image

$
0
0

I have a Ribbon toolbar added to my VS2012 (C++) project. I would like to use a certain toolbar button as a "state indicator", so that depending on the user's choice or some other conditions it would display different bitmaps (yes, I do not need a button functionality, but am too new to the Ribbon ideology to find a better way for doing so). What I am trying to do is:

1. I have a panel, containing the button A and checkbox B;
2. In CMainFrame::OnCreate() I create and load the CMFCRibbonBar instance.
    Then I either disable (state1), or enable and check (state 2), or enable and uncheck (state 3) the checkbox B - depending on my business logic
    Then I want to set the button A bitmap. To do it, I used code as follows:

    CMFCRibbonBar *pR = GetRibbonBar();
    CMFCButton *pB = (CMFCButton *)pR->FindByID( ID_BUTTON_STATE );
    ASSERT( pB != 0 );
    int btnId = GetBitmapId(); // Pulls the bitmap resource id
    HICON hI = (HICON)::LoadImage( AfxGetInstanceHandle(), 
                                   MAKEINTRESOURCE( btnId ),
                                   IMAGE_BITMAP,
                                   0, 0, LR_LOADTRANSPARENT );
    if( hI != 0 )
        pB->SetImage( hI );

// I also tried direct (initially)
// pR->SetImage( GetImageId() );
// instead, but it did not make any difference

3. On the checkbox B's "clicked" event handler, depending on the state I use the identical piece of code to replace the bitmap according to my logic.

It does not work... The program throws the exception inside

CMFCButton::ClearImages()

function, namely inside the 

CMFCToolBarImages::Clear()

because the m_lstOrigResIds (which is in fact CList) turns out to be unitialized.

I do not think I am the first who is trying to use the SetImage() but failed to find any hints regarding its correct use.
Hence, three questions:
1. What am I doing wrong replacing the button's bitmap?
2. Can I replace it with a larger bitmap?
3. Is there a better way to add this sort of an indicator to the Ribbon?

Thank you!


Mike Faynberg

what is this ? error C2143: syntax error : missing ';' before '.'

$
0
0
int main(array<System::String ^> ^args)
{
	// Enabling Windows XP visual effects before any controls are created
	Application::EnableVisualStyles();
	Application::SetCompatibleTextRenderingDefault(false); 

	// Create the main window and run it
	Application::Run(gcnew Form1());

error at this line -->		  Form1.textBox1="hello";//(MYREC*)pMyCDS->lpData;
	return 0;
}

hello dear forum

this above code gives folowing errors when compiling

1>.\receiving.cpp(48) : error C2143: syntax error : missing ';' before '.'

1>.\receiving.cpp(48) : error C2143: syntax error : missing ';' before '.'

how can I proceed ?

thank you 


Debugging generated assembly code stops working when I move code to a DLL

$
0
0

Hi --

I have some code that I'm trying to integrate with visual Studio inside a Visual Studio package extension.  In order to move this code to an extension package I had to take what was previously just part of a monolithic executable and move it into a separate DLL.  This code bootstraps my custom language engine and generates significant amounts of Intel assembly language code by writing bits to memory.  I eventually jump to an entry point in this generated assembly code and continue execution from there.

When this was all in one executable I had no problems setting breakpoints on and stepping into my generated Assembly language code.  But when I moved it into a separate DLL, although I could step through and set breakpoints on the C++ portion of the code, I ceased to be able to either step into or set breakpoints on the generated assembler language code.  This has nothing to do with it being packaged inside of a Visual Studio extension project, as I was able to demonstrate the same issue with calling my DLL from a very simple console app.

As soon as I moved the code back into a single executable debugging the assembly code started working again.  I really have to get this to work and have no choice but to use a DLL, as the Visual Studio package extension is itself a DLl.

I'm hoping that there is some setting somewhere that I am forgetting about or some simple code fix I can make to get this all to begin working again.  If anyone has any ideas for me, I would be most appreciative.

Thanks.

Mike

Saving HDC image data to a file, and creating an image from information retrieved from that file

$
0
0

Hi, I have a few questions regarding the use of HDC in C++.

1) Firstly, its about my title. Is it possible for me to save HDC info into a file, and recreate an image (eg. drawing it on a client rec using HDC) from those HDC info?

2) Assuming its possible in 1, I have tried coding, but nothing gets saved to my file (0 bytes). Where am I going wrong?

struct newBMPinfo { BITMAPINFO info; RGBQUAD moreColors[255]; } colors; void* getScreenCapture(int iXpixel, int iYpixel, int iBMPcolor, int* pSize) { void* cBmpData = NULL; if (iBMPcolor != 1 && iBMPcolor != 4 && iBMPcolor != 8 && iBMPcolor != 16 && iBMPcolor != 24 && iBMPcolor != 32) { printf("Please choose a color system from 1, 4, 8, 16, 24 or 32 bits."); } else { HDC hdcScreen; HDC hdcMemDC = NULL; HBITMAP hbmScreen = NULL; BITMAP bmpScreen; newBMPinfo bmpinfo; double fTempright, fTempbottom, fRatio, fbottomX, fbottomY; int itopX, itopY; hdcScreen = GetDC(NULL); hdcMemDC = CreateCompatibleDC(hdcScreen); hbmScreen = CreateCompatibleBitmap(hdcScreen, iXpixel, iYpixel); if (hdcMemDC && hbmScreen) { // Select the compatible bitmap into the compatible memory DC. SelectObject(hdcMemDC, hbmScreen); SetStretchBltMode(hdcMemDC, HALFTONE); //*******************setting new dimensions for scaling**************************** Setting the double and int variables here //*******************end of maths scaling code**************************** //Scale my image if (StretchBlt(hdcMemDC, itopX, itopY, (int)fbottomX, (int)fbottomY, hdcScreen, 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN), SRCCOPY)) {

                BITMAP bmpScreen;

                GetObject(hbmScreen, sizeof(BITMAP), &bmpScreen);

                bmpinfo.info.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
                bmpinfo.info.bmiHeader.biWidth = bmpScreen.bmWidth;
                bmpinfo.info.bmiHeader.biHeight = bmpScreen.bmHeight;
                bmpinfo.info.bmiHeader.biPlanes = 1;
                bmpinfo.info.bmiHeader.biBitCount = iBMPcolor;
                bmpinfo.info.bmiHeader.biCompression = BI_RGB;
                bmpinfo.info.bmiHeader.biSizeImage = 0;
                bmpinfo.info.bmiHeader.biXPelsPerMeter = 0;
                bmpinfo.info.bmiHeader.biYPelsPerMeter = 0;
                bmpinfo.info.bmiHeader.biClrUsed = 0;
                bmpinfo.info.bmiHeader.biClrImportant = 0;

                DWORD dwBmpSize = ((bmpScreen.bmWidth * bmpinfo.info.bmiHeader.biBitCount + 31) / 32) * 4 * bmpScreen.bmHeight;
                HANDLE hDIB = LocalAlloc(LMEM_FIXED, dwBmpSize);
                cBmpData = (unsigned char*)LocalLock(hDIB);

                // Gets the "bits" from the bitmap and copies them into a buffer
                GetDIBits(hdcScreen, hbmScreen, 0, (UINT)bmpScreen.bmHeight, cBmpData, &bmpinfo.info, DIB_RGB_COLORS);

                // A file is created, this is where we will save the screen capture.
                HANDLE hFile = CreateFile(L"bmpinfo", GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);

                // Add the size of the headers to the size of the bitmap to get the total file size
                DWORD dwSizeofDIB = dwBmpSize + sizeof(BITMAPFILEHEADER) + sizeof(bmpinfo);

                DWORD dwBytesWritten = 0;
                WriteFile(hFile, (LPSTR)cBmpData, dwBmpSize, &dwBytesWritten, NULL);

                //Unlock and Free the DIB from the heap
                LocalUnlock(hDIB);
                LocalFree(hDIB);

CloseHandle(hFile); } } //delete memory after use DeleteObject(hbmScreen); DeleteObject(hdcScreen); DeleteObject(hdcMemDC); ReleaseDC(NULL, hdcScreen); ReleaseDC(NULL, hdcMemDC); } return cBmpData; }

3) I have worked out the file reading part. Am I on the right track? How should I go about to display the image on my desktop?

void displayDC(int pSize)
{    DWORD bytesread;
    HANDLE file = CreateFile(L"bmpinfo", GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
    void* tempData;

    int iFilesize = GetFileSize(file, NULL);

    if (ReadFile(file, &tempData, iFilesize, &bytesread, NULL) == FALSE)
        printf("%d", GetLastError()); }

Thank you for your time in reading this.


What is DCAppConfig -> 'Enable' admin setting is not found.

$
0
0

I am using the guidance of this article to chase down missing header files, and my DebugView window is filled with thousands of the same message:

Info: DCAppConfig -> 'Enable' admin setting is not found. 

I am compiling a C++/MFC project in VS2010. I am trying to determine if this is a message I should be concerned about, and whether it indicates an issue with the settings for our projects.

ATL Aggregation Problem.

$
0
0

Hi,

I have put together a simple ATL aggregation example (below).

The inner interface IImplemntation is hosted by CImplementation. The outer interface IImplementation1 is hosted by CImplementation1. The inner IUnknown is created in CImplementation1::FinalConstruct(). The interface Map looks like that:

      BEGIN_COM_MAP(CImplementation1)

         COM_INTERFACE_ENTRY(IImplementation1)

         COM_INTERFACE_ENTRY_AGGREGATE(IID_IImplementation, m_pInnerUnk)

      END_COM_MAP()

Everything builds without warnings. CoCreateInstance for CLSID_Implementation returns S_OK, but QuerryInterface returns 0x80040155 for both inner and outer interfaces. (IID_Implementation and IID_Implementation1). What is wrong?

// Implementation.h : Declaration of the CImplementation

#pragma once
#include "resource.h"       // main symbols
#include "AtlAggregation_i.h"

using namespace ATL;
// CImplementation
// Inner Implementation
class ATL_NO_VTABLE CImplementation :
	public CComObjectRootEx<CComMultiThreadModel>,
	public CComCoClass<CImplementation, &CLSID_Implementation>,
	public IImplementation
{
public:
	CImplementation()
	{
	}

	DECLARE_REGISTRY_RESOURCEID(IDR_IMPLEMENTATION)


	BEGIN_COM_MAP(CImplementation)
		COM_INTERFACE_ENTRY(IImplementation)
	END_COM_MAP()



	DECLARE_PROTECT_FINAL_CONSTRUCT()

	HRESULT FinalConstruct()
	{
		return S_OK;
	}

	void FinalRelease()
	{
	}

public:
	STDMETHOD(Init)(void);
};

// CImplementation1
// Outer Implementation
class ATL_NO_VTABLE CImplementation1 :
	public CComObjectRootEx<CComMultiThreadModel>,
	public CComCoClass<CImplementation1, &CLSID_Implementation>,
	public IImplementation1
{
public:
	CImplementation1() :  m_pInnerUnk(NULL)
	{
	}

      DECLARE_GET_CONTROLLING_UNKNOWN()
      DECLARE_REGISTRY_RESOURCEID(IDR_IMPLEMENTATION)
      DECLARE_PROTECT_FINAL_CONSTRUCT()

      BEGIN_COM_MAP(CImplementation1)
         COM_INTERFACE_ENTRY(IImplementation1)
         COM_INTERFACE_ENTRY_AGGREGATE(IID_IImplementation, m_pInnerUnk)
      END_COM_MAP()

	HRESULT FinalConstruct()
	{
		HRESULT hr;
	    hr = CImplementation::_CreatorClass::CreateInstance(
             GetControllingUnknown(), IID_IUnknown,
             (void**)&m_pInnerUnk);
		return hr;
	}

	void FinalRelease()
	{
		m_pInnerUnk->Release();
	}

public:
	STDMETHOD(Init)(void);

private:
	LPUNKNOWN	m_pInnerUnk;
};

OBJECT_ENTRY_AUTO(__uuidof(Implementation), CImplementation1)


How to define a function that using extern “C” modifier

$
0
0

In a DLL, a function is exported, and it is defined as:

extern "C" ULONGLONG WINAPI MyFun(CONST LPVOID lpParam);

Now in My app, I need to get the address of the function and invoke it, so I use

typedef ULONGLONG (WINAPI *MyFun) (CONST LPVOID lpParam);

and use

lpMyFun = (MyFun)GetProcAddress(hDLL, "MyFun");

In such a way, there is no way to put the extern "C" modifier in the typedef codeline, I using

extern "C" typedef ULONGLONG (WINAPI *MyFun) (CONST LPVOID lpParam);

but that will cause compiler error.

How to solve the problem?

Thanks


detecting memory leaks

$
0
0

Visual Studio 2010, Windows 7, MFC, C++

My application exits with the following message in Output:

The thread 'Win32 Thread' (0x164c) has exited with code 0 (0x0).

Detected memory leaks!

Dumping objects ->

{356} normal block at 0x02D51A88, 2068 bytes long.

 Data: <   C           > CD 01 CD CD 43 00 00 00 01 01 CD CD 00 00 00 00

Object dump complete.

The program '[0x1558] Test_Server.exe: Native' has exited with code 0 (0x0).

Visual  Studio and Windows knows where each class is put in memory, where each new’ed structure is put, etc. Rather than providing just the address, it would be much more than just nice if the Output window had words to the effect:

By The Way, item X was loaded at that address.

I found this web page:  http://msdn.microsoft.com/en-us/library/x98tx3cf.aspx

And followed that advice.  There was much more information in the output window but the only thing that looked helpful was:

Detected memory leaks!

Dumping objects ->

{356} normal block at 0x02D21A88, 2068 bytes long.

 Data: <   C           > CD 01 CD CD 43 00 00 00 01 01 CD CD 00 00 00 00

f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\wincore.cpp(4553) : {255} client block at 0x002F8B98, subtype c0, 56 bytes long.

a CObject object at $002F8B98, 56 bytes long

{244} normal block at 0x002F86C0, 22 bytes long.

I did not write wincore.cpp and do not directly call it from my code. That does not help me locate the source of my error.

Further down on the page I find instructions to add this:

#ifdef _DEBUG

  #ifndef DBG_NEW

     #define DBG_NEW new ( _NORMAL_BLOCK , __FILE__ , __LINE__ )

     #definenew DBG_NEW

  #endif

#endif // _DEBUG

With that added the build process complains:

1>Test_ServerDlg.obj : error LNK2005: "void __cdecl operator delete(void *,int,char const *,int)" (??3@YAXPAXHPBDH@Z) already defined in uafxcwd.lib(afxmem.obj)

1>D:\BRYAN\Test_TCP_Thread\Debug\Test_Server.exe : fatal error LNK1169: one or more multiply defined symbols found

Does that mean the delete operator is multiply defined.  I searched my code and it is not defined in anything I wrote.  What might I do to resolve that issue so I can get back to the primary problem?

What can I do to help isolate the problem with my code?


~jag77 We need to know what a dragon is before we study its anatomy. (Bryan Kelly, 2010)


Need to convert VB 6.0 standard program to native C (not C++/C#)

$
0
0

Hello,

I got this code from here: http://msdn.microsoft.com/en-us/library/ms233639(v=vs.100).aspx

Option Explicit

Private Sub Command1_Click()
    Dim frm As COMWinform.COMForm
    Set frm = New COMWinform.COMForm
    frm.ShowForm1
End Sub

Since the article only gives a VB example, I created the whole solution in VB as they explain it.  I also created the VB 6.0 program to call the COM Interop that is being exposed and it works fine.

My problem is I would like to call the COM Interop from a plain "C" 6.0 program(not C#/C++).

Can anybody convert that bit of code to plain ANSI unmanaged C?

Any help would be gratefully appreciated.

Thanks,
Tony


Stop The World, I want To Get Off! ........... Life Isn't About Waiting For The Storm To Pass ... It's About Learning To Dance In The Rain.



Visual Studio 2012: LINK : fatal error LNK1181: cannot open input file ',.lib'

$
0
0

I've been encountering a strange bug in Visual Studio 2012 for some time now. I have a solution consisting of a project which compiles to a static library, and another project which is really simple but depends on this library. After Rebuilding the Solution or just compiling it with 1-3 changed source files, I get the following error:

LINK : fatal error LNK1181: cannot open input file ',.lib'Build FAILED.TimeElapsed00:00:00.34==========Build:0 succeeded,1 failed,0 up-to-date,0 skipped ==========

I don't have a file with the name ,.lib I have tried cleaning the solution, but that doesn't always work.

==========Clean:1 succeeded or up-to-date,0 failed,0 skipped,Completed*********************************************************************************

I try Rebuild after clean but nothing...

   LINK : fatal error LNK1181: cannot open input file ',.lib'Build FAILED.TimeElapsed00:00:51.54==========RebuildAll:0 succeeded,1 failed,0 skipped ==========

What is wrong here?

Getting access to the in memory binary image of a loaded DLL executable COM component

$
0
0
I want to create my own copy protection scheme and one aspect of this would be to prevent others from patching the executable code stored in a DLL file. The other aspects are sufficiently worked out. I want to be able to generate an MD5 hash of the loaded executable from its loaded binary image. Does anyone know how I can get access to the loaded binary image of a DLL file so that I can compute its MD5 hash? 

100% Accurate Display Screen OCR http://www.OCR4Screen.com

Visual Studio 2012:error LNK1117: syntax error in option 'MAPINFO:LINES'

$
0
0

Hi

i put in the Linker\Command line: /MAPINFO:EXPORTS /MAPINFO:LINES 

and i get this error:

error LNK1117: syntax error in option 'MAPINFO:LINES'

how to turn-on MAPINFO:LINES in the visual studio 2012?

ty.

CPaneDialog none resizable dialog and docking

$
0
0
Hi All,

I've got a search dialog in my application which is derived from CPaneDialog.

How do I force it to only be the width of the dialog as defined in the resource editor? Currently it seems to allow resizing from 0,0 to any size no matter what I do! CDockablePane::SetSizeMode(bool) has no effect and the documentation is a joke for this method.

SetMinSize stops it getting to small but nothing I do will prevent it getting to wide (ON_WM_SIZE, ON_WM_GETMINMAXINFO do nothing).

** Fixed - Deleting the registry settings for the app fixed this one **
Also I want it to dock on the right hand side of my main view, but calling  CFrameWndEx::DockPane(&m_wndSearch,AFX_IDW_DOCKBAR_RIGHT) has no effect either.

Help appreciated.

Thanks

Saving C++ Source files only

$
0
0

I am teaching a class of high school students using Visual Studio 2013.  We are learning C++.

When we did a "Hello World!" program and saved it, the files were huge.  I was told there is a setting that allows us to only save the C++ source code.  How do we do that?


Cannot create win32 Console Application

$
0
0

I'm using Windows 7 Home Premium and Visual C++ 2010 Express.

Every time I try to create a Visual C++ win32 console application project and then I go into the Win32 Application Wizard, it doesn't show the "current project setting"and I am unable to click "Finish" or "Cancel" there is no next button. 

I am following this tutorial I found and it's supposed to look like this.

This is my first time using Microsoft Visual C++ 2010 Express and I would very much appreciate to find out what I'm doing wrong and if I could have some help on what to do?  Or If I should re install or try Visual Studio 2010

Mooncrawler

 

Can I access to OnPaint of CChildView class in a thread that belongs to CMainFrm class?

$
0
0

Hello, I am Hoon-sup, Kim as a beginner for multi-thread.
I would like to use multi-thread MFC code which are consist of three threads(DAQThread, DSPThread, DRAWThread). As you can see in the bottom of this letter, there are three files which are MainFrm1.h, MainFrm1.cpp and ChildView1.cpp. This code can play a role in acquiring CCD camera data and then signal processing of it and last drawing the resultant image of it. When I push the play button, OnDaqOctplaying() function is called and the play button is toggled into stop button and the display shows me real time image at 10 frames per sec correctly.  However, as I want to finish the thread operation, and when I push the stop button which goes into botton part in OnDaqOctplaying(), 126byte size memory leak error occurs because the DRAWThread is terminated forcefully as you can see in the Debug mode Output display. I used global variable such as DAQThreadFlag, DSPThreadFlag and DRAWThreadFlag to finish each thread by itself. However I don't know why the DRAWThread is not finished by itself. I want to know whether it is correct that I am calling RedrawWindow() function in DRAWThread which belongs to CMainFrm class. 

CChildView *pView = (CChildView *)pParam;

pView->RedrawWindow(NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW);

Is it correct thatI use CChildView *pView when I want to call OnPaint() function of CChildView class in a thread of CMainFrame class?

When I try to finish DRAWThread by itself via global variables, it seems like deadlock and then finally WAIT_TIMEOUT happened.

According to a book about MFC multi-thread, it is said that when we need to access to Main frame window or View window in a specific worker thread under multi-thread, User defined message is recommended to use. For examples,GetActiveView()->PostMessage(....) But there is no any reason why I use User defined message in this situation and I have no any idea about how to implement it in detail.

Please let me know which part or structure of the code that I attached is not correct and do I need toexplicitly write NULL to Handle of DRAWThread right before finishing it?

Thank you very much any way. 


----Debug mode Output display:----------------------------------------

DAQ Thread End
The thread 'Win64 Thread' (0xd50) has exited with code 0 (0x0).
pDAQThread is terminated normally
pDAQThread is terminated(code=0)
DSP Thread End
The thread 'Win64 Thread' (0x17b4) has exited with code 0 (0x0).
pDSPThread is terminated normally
pDSPThread is terminated(code=0)
pDRAWThread is terminated FORCELY!!!
The thread 'Win64 Thread' (0x17c8) has exited with code 0 (0x0).
pDRAWThread is terminated(code=259)
The thread 'Win64 Thread' (0x17f4) has exited with code 0 (0x0).
all thread finish?...
Warning: no message line prompt for ID 0x800C.
Warning: no message line prompt for ID 0x800D.
Warning: no message line prompt for ID 0x801F.
Warning: no message line prompt for ID 0x800E.
Warning: no message line prompt for ID 0x800F.
Warning: no message line prompt for ID 0x8010.
Warning: no message line prompt for ID 0x8011.
Warning: no message line prompt for ID 0x801B.
Warning: no message line prompt for ID 0x800C.
Warning: no message line prompt for ID 0x800D.
Warning: no message line prompt for ID 0x801F.
Warning: no message line prompt for ID 0x800E.
Warning: no message line prompt for ID 0x800F.
Warning: no message line prompt for ID 0x8010.
Warning: no message line prompt for ID 0x8011.
Warning: no message line prompt for ID 0x801B.
The thread 'Win64 Thread' (0x1588) has exited with code 0 (0x0).
The thread 'Win64 Thread' (0x9ac) has exited with code 0 (0x0).
The thread 'Win64 Thread' (0xc48) has exited with code 0 (0x0).
I am OnDestroy!!!
The thread 'Win64 Thread' (0xc20) has exited with code 0 (0x0).
Detected memory leaks!
Dumping objects ->
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\thrdcore.cpp(306) : {1318} client block at 0x00000000074DFC00, subtype c0, 136 bytes long.
a CWinThread object at $00000000074DFC00, 136 bytes long
Object dump complete.
The thread 'Win64 Thread' (0xea0) has exited with code 0 (0x0).
The thread 'Win64 Thread' (0x63c) has exited with code 0 (0x0).
The thread 'Win64 Thread' (0x13d4) has exited with code 0 (0x0).
The thread 'Win64 Thread' (0x15c8) has exited with code 0 (0x0).
The thread 'Win64 Thread' (0x1664) has exited with code 0 (0x0).
The thread 'Win64 Thread' (0x120c) has exited with code 0 (0x0).
The thread 'Win64 Thread' (0xc78) has exited with code 0 (0x0).
The thread 'Win64 Thread' (0xf6c) has exited with code 0 (0x0).
The thread 'Win64 Thread' (0x1408) has exited with code 0 (0x0).
The thread 'Win64 Thread' (0x11fc) has exited with code 0 (0x0).
The thread 'Win64 Thread' (0x1560) has exited with code 0 (0x0).
The thread 'MxsProxyGC' (0x1514) has exited with code 0 (0x0).
The thread 'Win64 Thread' (0x1074) has exited with code 0 (0x0).
The thread 'Win64 Thread' (0x10fc) has exited with code 0 (0x0).
The thread 'MxsProxyPump' (0x128c) has exited with code 0 (0x0).
The thread 'Win64 Thread' (0x166c) has exited with code 0 (0x0).
The thread 'Win64 Thread' (0x1558) has exited with code 0 (0x0).
The thread 'Win64 Thread' (0xb34) has exited with code 0 (0x0).
The thread 'Win64 Thread' (0x131c) has exited with code 0 (0x0).
The thread 'Win64 Thread' (0xb28) has exited with code 0 (0x0).
The thread 'Win64 Thread' (0x101c) has exited with code 0 (0x0).
The thread 'Win64 Thread' (0x1098) has exited with code 0 (0x0).
The thread 'Win64 Thread' (0x16ec) has exited with code 0 (0x0).
The thread 'Win64 Thread' (0x1744) has exited with code 0 (0x0).
The thread 'Win64 Thread' (0x16a0) has exited with code 0 (0x0).
The thread 'Win64 Thread' (0xf0c) has exited with code 0 (0x0).
The thread 'Win64 Thread' (0x15dc) has exited with code 0 (0x0).
The thread 'Win64 Thread' (0x484) has exited with code 0 (0x0).
The thread 'Win64 Thread' (0x150c) has exited with code 0 (0x0).
The program '[3132] Real OCT and ODT.exe: Native' has exited with code 0 (0x0).

//MainFrm1.h start //////////////////////////////////////
class CMainFrame : public CFrameWnd
{
public:
	CMainFrame();

protected: 
	DECLARE_DYNAMIC(CMainFrame)

// Attributes
public:

// Operations
public:

// Overrides
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CMainFrame)
	virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
	virtual BOOL OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo);
	//}}AFX_VIRTUAL

// Implementation
public:

	void ReOpen();
	virtual ~CMainFrame();
	int MotionControl;

//	CxImage *m_pMergingCanvas;

#ifdef _DEBUG
	virtual void AssertValid() const;
	virtual void Dump(CDumpContext& dc) const;
#endif

protected:  // control bar embedded members
	CStatusBar  m_wndStatusBar;
	CToolBar    m_wndToolBar;
	CReBar      m_wndReBar;
	CDialogBar  m_wndDlgBar;
	CChildView  m_wndView;

// Generated message map functions
//	protected:
public:

	afx_msg void OnDaqOctplaying();
	afx_msg BOOL MultiThreadMaking();

	static UINT DRAWThread(LPVOID pParam);
	static UINT DAQThread(LPVOID pParam);
	static UINT DSPThread(LPVOID pParam);
//	static UINT StopThread(LPVOID lpdwParam);

	static void Wait(DWORD);

	afx_msg void Messagebox_test(void);
	afx_msg void OnFilepath();
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()

	int PIStageID;

	void OnBgBLACK(void);

	bool m_MergingCheck;
	afx_msg void OnEnChangeBrightness();
	afx_msg void OnEnChangeContrast();
	afx_msg void OnBnClickedFringebg();
};
//MainFrm1.h end////////////////////////////////////////////


//MainFrm1.cpp start //////////////////////////////////////
CWinThread *pDAQThread = NULL;
CWinThread *pDSPThread = NULL;
CWinThread *pDRAWThread = NULL;

//MultiThread variable
static bool volatile startFlag = false;
static bool volatile DAQThreadFlag, DSPThreadFlag, DRAWThreadFlag;

CEvent Event_DAQ, Event_DSP, Event_DRAW, Event_STOP;

static uInt16	*user_buff;
static Int8         *ImaqBuffers[NUM_RING_BUFFERS];   // acquisiton buffer

UINT CMainFrame::DAQThread(LPVOID pParam)
{
	HANDLE hProcess;		// Current process handle
	hProcess = GetCurrentProcess();
	//SetPriorityClass(hProcess, HIGH_PRIORITY_CLASS);
	SetPriorityClass(hProcess, REALTIME_PRIORITY_CLASS);
	int i, j;

	CMainFrame *pIMAQError = (CMainFrame *)pIMAQError;
	CMainFrame *pDAQError = (CMainFrame *)pDAQError;
	int32       DAQerror=0;
	int			IMAQerror=0;
	char        errBuff[2048]={'\0'};

    int bufferIndex = 0;
	uInt32 currBufNum;
	void* bufAddr = NULL;

	while(startFlag == true)
	{
		while(DAQThreadFlag == true)
		{
			Event_DAQ.Lock();

				errChk(imgSessionExamineBuffer2 (Sid, bufferIndex, &currBufNum, &bufAddr));
				user_buff = (uInt16 *) bufAddr;
				// reinsert the buffer back in the ring
				errChk(imgSessionReleaseBuffer (Sid));

				// Now get next buffer
				bufferIndex ++;

				Event_DSP.PulseEvent();
		}
		DSPThreadFlag = false;
		DRAWThreadFlag = false;
	}

	TRACE("DAQ Thread End\n");
	return 0;

}

UINT CMainFrame::DSPThread(LPVOID pParam)
{
	BOOL err;
	float temp1, temp2;
	unsigned short bmpCount=0;

	while(startFlag==true)
	{
		while(DSPThreadFlag==true)
		{
			Event_DSP.Lock();

			if(iProgStatus == 8)  //OCT displaying
			{
				int i, j, k;

				Ipp32f *data1, *data3Re, *data3Im, *spectrumRe, *spectrumIm, *magnitude;

				#pragma omp parallel private(i, j, k, data1, temp1, temp2, spectrumRe, spectrumIm, data3Re, data3Im, magnitude)//, pOCTAscanSpec)
				{
					data1 = (float*)calloc(iCount, sizeof(float));
					spectrumRe = (float*)calloc(iCount, sizeof(float));
					spectrumIm = (float*)calloc(iCount, sizeof(float));
					data3Re = (float*)calloc(iCount, sizeof(float));
					data3Im = (float*)calloc(iCount, sizeof(float));
					magnitude = (float*)calloc(HeightPixel, sizeof(float));

					#pragma omp for
					for(i=0;i<XRange;i++) 
					{
						for (j=0; j<iCount-1; j++) //interpolation
						{
							temp1= *(user_buff + index[j]+i*iCount)-m_ibackground[index[j]]; 
							temp2= *(user_buff + index[j]+1+i*iCount)-m_ibackground[index[j]+1];
							data3Re[j]=temp1+(temp2-temp1)*k2LambdaRate[j];//(klambda[k]-lambda[index[k]])/(lambda[index[k]+1]-lambda[index[k]]);//*cosfDispersion[j];
							data3Im[j]=0;
						}
						data3Re[iCount-1] = *(user_buff + iCount-1+i*iCount)-m_ibackground[iCount-1];

						data3Im[iCount-1] = 0.0;

						ippsMul_32f_I(win, data3Re, iCount);

						ippsFFTFwd_CToC_32f(data3Re, data3Im, spectrumRe, spectrumIm, FFTspecification, NULL);

						ippsMagnitude_32f(spectrumRe, spectrumIm, magnitude, HeightPixel);//500*700 pixel

						ippsSub_32f(pOCTBackGround[i], magnitude, magnitude, HeightPixel);

						ippsFlip_32f_I(magnitude, HeightPixel);

						ippsThreshold_LTVal_32f_I(magnitude, HeightPixel, 1.0e-10, 0.0);
						ippsLog10_32f_A11(magnitude, magnitude, HeightPixel);
						ippsMulC_32f_I(10.0, magnitude, HeightPixel);

						ippsAddC_32f_I(dBrightness, magnitude, HeightPixel);//dBrightness
						ippsMulC_32f_I(dContrast, magnitude, HeightPixel);//dContrast

						ippsThreshold_LTValGTVal_32f_I(magnitude, HeightPixel, 0.0, 0.0, 255.0, 255.0);

						ippsCopy_32f(magnitude, pOCTAscanSpec[i], HeightPixel);
					}
					free(data1);
					free(spectrumRe);
					free(spectrumIm);
					free(data3Re);
					free(data3Im);
					free(magnitude);
				}
				ippsJoin_32f16s_D2L((const Ipp32f**) pOCTAscanSpec, XRange, HeightPixel, ipp_1d_16s);
				ippsConvert_16s32f_Sfs(ipp_1d_16s, ipp_1d_32f, XRange*HeightPixel, 0);
				ippsConvert_32f8u_Sfs(ipp_1d_32f, lpBmpOCT, XRange*HeightPixel, ippRndZero, 0);
			}

			Event_DRAW.PulseEvent();
/		}
		DRAWThreadFlag = false;
		DAQThreadFlag = false;
	}

	TRACE("DSP Thread End\n");
	return 0;

}

UINT CMainFrame::DRAWThread(LPVOID pParam) // ADC performance for OCT displaying
{

//	CChildView *pView = (CChildView *)pParam;

	int DrawTime = 1;

	int			IMAQerror=0;

	while(startFlag == true)
	{
		while(DRAWThreadFlag == true)
		{
			Event_DRAW.Lock();

			QueryPerformanceFrequency( &DRAWFrequency );
			QueryPerformanceCounter( &DRAWBeginTime ); 

//			pView->RedrawWindow(NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW);

			QueryPerformanceCounter( &DRAWEndtime );
			DRAWelapsed = DRAWEndtime.QuadPart- DRAWBeginTime.QuadPart; 
			timeDRAWResult = (double)DRAWelapsed / (double)DRAWFrequency.QuadPart*1000.0;

			Event_DAQ.PulseEvent();
		}
		DSPThreadFlag = false;
		DAQThreadFlag = false;
	}

	TRACE("DRAW Thread End\n");

	return 0;
}


BOOL CMainFrame::MultiThreadMaking()
{
		pDAQThread = AfxBeginThread(DAQThread, (LPVOID)this);
		pDSPThread = AfxBeginThread(DSPThread,(LPVOID)this);
		pDRAWThread = AfxBeginThread(DRAWThread,(LPVOID)this);

		Event_DAQ.PulseEvent();

		return 0;
}


void CMainFrame::OnDaqOctplaying()  //iProgStatus==8
{	
	if(iProgStatus == 1) 
	{
		m_wndDlgBar.SetDlgItemText(IDC_PLAY, "STOP"); 		// Set caption of button to "STOP"
		iProgStatus = 8;

		iBufferStatus = 0;

		// Allocate memory for bitmap 
		if(hDIB1 != NULL) hDIB1 = GlobalFree(hDIB1);
		hDIB1 = GlobalAlloc(GMEM_MOVEABLE, sizeof(BITMAPINFOHEADER) + 256*sizeof(RGBQUAD) + XRange*HeightPixel);//(int)((iCount)/2.0));
		lpBmpOCT = (BYTE *)GlobalLock(hDIB1);

////////////////////////////////////////////////////////////////////////////////////////
			// Write BITMAPINFOHEADER
		lpDIBInfoOCT = (LPBITMAPINFOHEADER)lpBmpOCT;
		lpDIBInfoOCT->biSize = sizeof(BITMAPINFOHEADER);
		lpDIBInfoOCT->biWidth = XRange;
		lpDIBInfoOCT->biHeight = HeightPixel;//(int)((iCount)/2.0);//(int)((iCount - 1)/3.0); // Why divide it by 5
		lpDIBInfoOCT->biPlanes = 1;
		lpDIBInfoOCT->biBitCount = 8;
		lpDIBInfoOCT->biCompression = BI_RGB;
		lpDIBInfoOCT->biSizeImage = XRange*lpDIBInfoOCT->biHeight;
		lpDIBInfoOCT->biXPelsPerMeter = 0;
		lpDIBInfoOCT->biYPelsPerMeter = 0;
		lpDIBInfoOCT->biClrUsed = 256;
		lpDIBInfoOCT->biClrImportant = 0;
		// Write color table
		// Write Color table

		RGBQUAD *bmiColors;	
		bmiColors = (RGBQUAD *) (lpBmpOCT + sizeof(BITMAPINFOHEADER));
		unsigned int i;
		for(i=0;i<256;i++,bmiColors++)
		{
			bmiColors->rgbBlue = i;
			bmiColors->rgbGreen = i;
			bmiColors->rgbRed = i;
			bmiColors->rgbReserved = 0;
		}
		lpBmpOCT = lpBmpOCT + sizeof(BITMAPINFOHEADER) + 256*sizeof(RGBQUAD);

		//***** Create Task for Frame grabber & DAQ board (3/7/2008)
		errChk(imgInterfaceOpen("img0", &Iid));
		errChk(imgSessionOpen(Iid, &Sid));

		//**** Set the ROI to obtain spectrum
		AcqWinWidth = iCount;
		AcqWinHeight = XRange;

		// Set the ROI to the size of the Canvas so that it will fit nicely
		errChk(imgSetAttribute2 (Sid, IMG_ATTR_ROI_WIDTH, AcqWinWidth));
		errChk(imgSetAttribute2 (Sid, IMG_ATTR_ROI_HEIGHT, AcqWinHeight));
		errChk(imgSetAttribute2 (Sid, IMG_ATTR_ROWPIXELS, AcqWinWidth));

		// create a buffer list with one element
		errChk(imgCreateBufList(NUM_RING_BUFFERS, &Bid));
		// compute the size of the required buffer
		errChk(imgGetAttribute (Sid, IMG_ATTR_BYTESPERPIXEL, &bytesPerPixel));
		bufSize = AcqWinWidth * AcqWinHeight * bytesPerPixel;

		for (int i = 0; i < NUM_RING_BUFFERS; i++)
		{
			errChk(imgCreateBuffer(Sid, FALSE, bufSize, (void**)&ImaqBuffers[i]));
			errChk(imgSetBufferElement2(Bid, i, IMG_BUFF_ADDRESS, ImaqBuffers[i]));
			errChk(imgSetBufferElement2(Bid, i, IMG_BUFF_SIZE, bufSize));
			bufCmd = (i == (NUM_RING_BUFFERS - 1)) ? IMG_CMD_LOOP : IMG_CMD_NEXT;
			errChk(imgSetBufferElement2(Bid, i, IMG_BUFF_COMMAND, bufCmd));
		}

		// lock down the buffers contained in the buffer list
		errChk(imgMemLock(Bid));

		// Tell the acquisition to use a line trigger, which should be derived from the IMG_SIGNAL_EXTERNAL.
		errChk(imgSessionLineTrigSource2(Sid, IMG_SIGNAL_EXTERNAL, 0, IMG_TRIG_POLAR_ACTIVEH, 0));

		// configure the session to use this buffer list
		errChk(imgSessionConfigure(Sid, Bid));

		// start the acquisition, asynchronous
		errChk(imgSessionAcquire(Sid, TRUE, NULL));

		if(startFlag == true)
			return;

		startFlag = true;
			
		DAQThreadFlag = true;
		DSPThreadFlag = true;
		DRAWThreadFlag=true;

		MultiThreadMaking();  //Make three threads

		return;

	}

	if(iProgStatus == 8) 
	{
		// Stop the threads
		startFlag = false;
		DAQThreadFlag = false;

		DWORD dwRetCode;
		DWORD dwExitCode = 0;

		dwRetCode = ::WaitForSingleObject(pDAQThread->m_hThread, 3000);
		if(dwRetCode == WAIT_OBJECT_0)
		{
		 TRACE("pDAQThread is terminated normally\n");
		}
		else if(dwRetCode == WAIT_TIMEOUT) 
		{
		 ::TerminateThread(pDAQThread->m_hThread, 0 );
		 TRACE("pDAQThread is terminated FORCELY!!!\n");
		}
		if(pDAQThread)
		{
		 GetExitCodeThread(pDAQThread->m_hThread, &dwExitCode);
		 TRACE("pDAQThread is terminated(code=%d)\n", dwExitCode);
//		 delete pThread;   // m_bAutoDelete = FALSE의 경우 스레드의 삭제를 잊지말자. 
		}

		dwRetCode = ::WaitForSingleObject(pDSPThread->m_hThread, 3000);
		if(dwRetCode == WAIT_OBJECT_0)
		{
		 TRACE("pDSPThread is terminated normally\n");
		}
		else if(dwRetCode == WAIT_TIMEOUT) 
		{
		 ::TerminateThread(pDSPThread->m_hThread, 0 );
		 TRACE("pDSPThread is terminated FORCELY!!!\n");
		}
		if(pDSPThread)
		{
		 GetExitCodeThread(pDSPThread->m_hThread, &dwExitCode);
		 TRACE("pDSPThread is terminated(code=%d)\n", dwExitCode);
//		 delete pThread;   // m_bAutoDelete = FALSE의 경우 스레드의 삭제를 잊지말자. 
		}

		dwRetCode = ::WaitForSingleObject(pDRAWThread->m_hThread, 3000);
		if(dwRetCode == WAIT_OBJECT_0)
		{
		 TRACE("pDRAWThread is terminated normally\n");
		}
		else if(dwRetCode == WAIT_TIMEOUT) 
		{
		 ::TerminateThread(pDRAWThread->m_hThread, 0 );
		 TRACE("pDRAWThread is terminated FORCELY!!!\n");
		}
		if(pDRAWThread)
		{
		 GetExitCodeThread(pDRAWThread->m_hThread, &dwExitCode);
		 TRACE("pDRAWThread is terminated(code=%d)\n", dwExitCode);
//		 delete pThread;   // m_bAutoDelete = FALSE의 경우 스레드의 삭제를 잊지말자. 
		}

		// stop the acquisition
		imgSessionAbort(Sid, NULL);

		// unlock the buffers in the buffer list
		if (Bid != 0)
			imgMemUnlock(Bid);

		// dispose of the buffers 
		for (int i = 0; i < NUM_RING_BUFFERS; i++)
			if (ImaqBuffers[i] != NULL)
				imgDisposeBuffer(ImaqBuffers[i]);

		// close this buffer list
		if (Bid != 0)
			imgDisposeBufList(Bid, FALSE);

		// Close the interface and the session
		if(Sid != 0)
			imgClose (Sid, TRUE);
		if(Iid != 0)
			imgClose (Iid, TRUE);

		// Reset the session variables.
		Sid = Bid = Iid = 0;

		iProgStatus = 1;
		iBufferStatus = 2;
		m_wndDlgBar.SetDlgItemText(IDC_PLAY, "PLAY"); 		// Set caption of button to "PLAY"

		return;
	}
	return;
}
//MainFrm1.cpp end

//ChildView1.cpp start
CChildView::CChildView()
{
	hDrawView = DrawDibOpen();
	hDrawView1 =DrawDibOpen();
	hDrawView2 =DrawDibOpen();
}

CChildView::~CChildView()
{
	DrawDibClose(hDrawView);
	DrawDibClose(hDrawView1);
	DrawDibClose(hDrawView2);
}

void CChildView::OnPaint() 
{
	CPaintDC dc(this); // device context for painting
//	CMemDC pDC(dc);

	int iXOffset1=10, iYOffset1=10, iXOffset2=10, iYOffset2=10;
	
	// TODO: Add your message handler code here

	BYTE *lpBmp;
	LPBITMAPINFOHEADER lpDIBInfo;
	int iXOffset=10, iYOffset=10;
	int iXWidth, iYHeight;
	double fPropotion;

	CRect cWndRect;
	GetWindowRect(cWndRect);

	POINT axis;
	axis.x = cWndRect.Width();
	axis.y = cWndRect.Height();

	if(iProgStatus == 8) { //OCT playing
		iXOffset = (int) (0.1*cWndRect.Width());
		fPropotion = 0.5*cWndRect.Width()/(lpDIBInfoOCT->biWidth);//0.7
		iXWidth = (int) (fPropotion*(lpDIBInfoOCT->biWidth));
		iYHeight =  (int) 0.3*(lpDIBInfoOCT->biHeight);

			fPropotion=1;

			if (0.8*axis.y*fPropotion < axis.x*0.8)
			{
				iYHeight = (int) (axis.y*0.8);
				iXWidth = (int) (fPropotion*iYHeight);			
			}
			else 
			{
				iXWidth = (int) (axis.x*0.8);
				iYHeight = (int) (iXWidth/fPropotion);
			}
			iXWidth = (int)(iXWidth/4.0*4);
			iYHeight=(int)(iYHeight/4.0*4);

		DrawDibDraw(hDrawView, dc.m_hDC, iXOffset, iYOffset, iXWidth, 
			iYHeight, lpDIBInfoOCT, lpBmpOCT, 0, 0, 
			lpDIBInfoOCT->biWidth, lpDIBInfoOCT->biHeight, DDF_ANIMATE);

		dc.TextOut(1024,200,performance1);
		dc.TextOut(1024,250,performance2);
		dc.TextOut(1024,300,performance3);
	}
	// Do not call CWnd::OnPaint() for painting messages
}

//ChildView1.cpp end //////////////////////////////////////










SAL in default "Win32 Console Application" template

$
0
0

The default "Win32 Console Application" template looks like this:

// SALTEST.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"

int _tmain(int argc, _TCHAR* argv[])
{
	return 0;
}

There are no SAL annotations! What would the proper annotations be? I imagine something like:

int _tmain( _In_ int argc, _In_reads_( argc ) _TCHAR* argv[ ] )
{
	return 0;
}

And by extension, what would be the equivalent for a `wchar_t** argv`? There isn't a `_Deref_in_reads( count )`, so I imagine it'd be something like `_Deref_prepost_count_( argc )`?

I think microsoft would see better adoption of SAL if it were included in default templates.

accessing server files

$
0
0

just starting out and wondered if anyone could point me in the right direction?

I have a simple name.txt file on my server containing comma separted names and I want a local C++ app to
check if a name is in the name.txt file?

Also is it possible to write/update to this file from the local app?

Choosing a Threading Model for in In-Process COM Server acting as a webservice

$
0
0

The COM Server only takes about 2 MB of space for itself and another 2 MB its space for its data. The server has 2 GB of dedicated RAM and one dedicated processor core. The longest process takes about 12 CPU seconds, this will occur rarely. The short processes take about 1 CPU second. I expect no more than 12 concurrent users. Each process must have its own data. The data is loaded from disk, so I want it to remain resident until the user logs off, or explicitly loads a different data file.

I am guessing the apartment level threading should work fine because it has its own message pump. I am not sure of the best way to handle the data. Currently it is stored in a global std::vector. I am pretty sure that this will be a problem for multiple concurrent processes. The easy solution would seem to be to put the loading of the data and the storage of the data in a single COM callable function. Combined with apartment level threading (which I assume invokes the functions from a FIFO queue) this should keep the data separate for every user because the std::vector data is stored on the system stack.

The problem with this whole scenario is the performance hit of loading from disk every time the 1 second process is invoked. In some cases the data might greatly exceed 2 MB. How can I best handle the data to fully enable multiple concurrent processes and get rid of this performance hit? 

It might even be OK to have multiple copies of the DLL executable loaded (one for each process) since each one takes so little space. Each one of these could have its own global data. 


100% Accurate Display Screen OCR http://www.OCR4Screen.com





Viewing all 15302 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>