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

How to make two window two window stick together

$
0
0

Hello All,

I want to make two window stick together. that is when A window moves or the size changes, B window will change it's location and size to stick to A window. when  A window is active, B window will change it's z order to most top to avoid to be masked by other windows.

The first requirement is easy to meet, I just handle WM_MOVE and WM_SIZE message of A window to change position and size of B. But the z order of B window is unchanged, that is not I want.

Thanks in advance.


Interaction in console window from Test methods

$
0
0

Hi,

I have been researching how to enable the console when a Unit Test DLL is loaded to execute a TEST_METHOD, with no success. I am using CppUnitTestFramework with Visual C++ from Visual Studio 2015 update 2.

I thought maybe posting here directly to Visual C++ experts (NOTE: it is native UNMANAGED C++ I am interested in only), maybe I could get some more useful feedback...

Regards,

Juan


Juan Dent


Android C++ Dynamic Shared Library multi-arch APK

$
0
0

Hi,

Is it possible to generate a dynamic library for each architecture (armv7a, arm64, x86...) from a Dynamic Shared Library project? I currently use a command line ndk-build setup called as a pre-build step to my Xamarin project to do this, but I'd like to be able to do it all in the IDE to make debugging easier, however I can't see a way of generating a library for each architecture like I can with the NDK, short of having separate projects for each arch and referencing them all. Is that the only way to do it?

Any help would be appreciated, surely someone else has come across this issue.

Thanks,

Simon


DAO: Record Locking problem?

$
0
0

I am using DAO with Visual C++ to access an Oracle DB via ODBC defined as a System DSN in the ODBC Data Source Administrator. My program is the sole user of the database.  I am the sole user of the system. I only have one program that accesses the database. It (at least in my code) is not multi-threaded.

I am trying to update a number of fields in a record.  I use the sequence of calls:

RecordSet->Edit();
For each field to be updated:  Fields->GetItem( <FieldIndex> )->Value = <value>;
RecordSet->Update(DAO::dbUpdateRegular, false);

One of the fields being updated is a floating point number.  Most of the time it works OK but depending on the previous value of that floating point field I sometimes get an exception on the Update() call:

"The Microsoft Access database engine stopped the process because you and another user are attempting to change the same data at the same time."

An example previous value that causes this to happen is 68.6. (There are other numbers).  This happens however that previous value is put in - e.g., with a previous run of the program, or by using SQL Developer.  It also happens regardless of whether the RecordSet is opened with pessimistic or optimistic locking.  

The error can be cleared by using Execute SQL UPDATE statement instead of Edit() .. Update().

I know this sounds crazy.  But this is 100% repeatable.  If the previous value of the floating point field is one of the problem numbers - Ialways get the problem.  If the previous value is NOT one of problem ones, Inever get the problem.  I can run a test program multiple times putting in a selected value with no problem.  As soon as I run it putting in 68.6 - the next time I run it I get the exception.

How can I diagnose the problem?   Has  something like this been seen before? Thanks.

How to Zoom A image Using WM_POINTER??

$
0
0
I am totally stuck with this problem ,trying to zooming the image using WM_POINTER.

error LNK2019: During the compilation of my projects

$
0
0

Hi .....

I am using Visual c++ 2010 in my project work for CFD coding.But during compilation i get the following errors 

error LNK2019: unresolved external symbol "public: __thiscall Array1D::~Array1D(void)" (??1Array1D@@QAE@XZ) referenced in function "void __cdecl setCoefficient(class Grid &,double)" (?setCoefficient@@YAXAAVGrid@@N@Z)
1>weavy.obj : error LNK2019: unresolved external symbol "public: double & __thiscall Array3D::operator()(int,int,int)" (??RArray3D@@QAEAANHHH@Z) referenced in function "void __cdecl setCoefficient(class Grid &,double)" (?setCoefficient@@YAXAAVGrid@@N@Z)
1>weavy.obj : error LNK2019: unresolved external symbol "public: double & __thiscall Array1D::operator()(int)" (??RArray1D@@QAEAANH@Z) referenced in function "void __cdecl setCoefficient(class Grid &,double)" (?setCoefficient@@YAXAAVGrid@@N@Z)
1>weavy.obj : error LNK2019: unresolved external symbol "public: class Array1D & __thiscall Array1D::operator=(class Array1D &)" (??4Array1D@@QAEAAV0@AAV0@@Z) referenced in function "void __cdecl setCoefficient(class Grid &,double)" (?setCoefficient@@YAXAAVGrid@@N@Z)
1>weavy.obj : error LNK2019: unresolved external symbol "public: __thiscall Array1D::Array1D(void)" (??0Array1D@@QAE@XZ) referenced in function "void __cdecl setCoefficient(class Grid &,double)" (?setCoefficient@@YAXAAVGrid@@N@Z)
1>weavy.obj : error LNK2019: unresolved external symbol "public: __thiscall Array1D::Array1D(int)" (??0Array1D@@QAE@H@Z) referenced in function "public: void __thiscall Grid::createGrid(void)" (?createGrid@Grid@@QAEXXZ)
1>weavy.obj : error LNK2019: unresolved external symbol "public: __thiscall Array3D::~Array3D(void)" (??1Array3D@@QAE@XZ) referenced in function __unwindfunclet$??0U_Equation@@QAE@AAVGrid@@AAVArray3D@@N@Z$0
1>weavy.obj : error LNK2019: unresolved external symbol "public: __thiscall Array3D::Array3D(class Array3D &)" (??0Array3D@@QAE@AAV0@@Z) referenced in function "public: __thiscall U_Equation::U_Equation(class Grid &,class Array3D &,double)" (??0U_Equation@@QAE@AAVGrid@@AAVArray3D@@N@Z)
1>weavy.obj : error LNK2019: unresolved external symbol "public: class Array3D & __thiscall Array3D::operator=(double)" (??4Array3D@@QAEAAV0@N@Z) referenced in function "public: void __thiscall U_Equation::initialize(void)" (?initialize@U_Equation@@QAEXXZ)
1>weavy.obj : error LNK2019: unresolved external symbol "public: class Array3D & __thiscall Array3D::operator=(class Array3D &)" (??4Array3D@@QAEAAV0@AAV0@@Z) referenced in function "public: void __thiscall U_Equation::initialize(class Array3D &)" (?initialize@U_Equation@@QAEXAAVArray3D@@@Z)
1>weavy.obj : error LNK2019: unresolved external symbol "public: __thiscall Array3D::Array3D(void)" (??0Array3D@@QAE@XZ) referenced in function "public: void __thiscall U_Equation::correction(class P_Equation &)" (?correction@U_Equation@@QAEXAAVP_Equation@@@Z)
1>weavy.obj : error LNK2019: unresolved external symbol "public: class Array1D & __thiscall Array1D::operator=(double)" (??4Array1D@@QAEAAV0@N@Z) referenced in function "public: double __thiscall U_Equation::mean(class P_Equation &,double)" (?mean@U_Equation@@QAENAAVP_Equation@@N@Z)
1>weavy.obj : error LNK2019: unresolved external symbol "public: __thiscall Array3D::Array3D(int,int,int)" (??0Array3D@@QAE@HHH@Z) referenced in function "public: void __thiscall P_Equation::coefficient(class U_Equation &,class V_Equation&,class W_Equation &)" (?coefficient@P_Equation@@QAEXAAVU_Equation@@AAVV_Equation@@AAVW_Equation@@@Z)
1>weavy.obj : error LNK2019: unresolved external symbol "public: __thiscall Array1D::Array1D(class Array1D &)" (??0Array1D@@QAE@AAV0@@Z) referenced in function _main
1>E:\HX\VS\heatexchanger\Debug\heatexchanger.exe : fatal error LNK1120: 14 unresolved externals

i have tried a lot by searching documentations from MSDN but unable to resolve this please anyone tell me i will be highly acknowledged....................

Deserialization fails from a COM EXE

$
0
0

Hi All, 

I have a file which has been created by MFC serialization by another module. Now I am trying to read the module from a function within a COM Exe. But the Serialize function fails with the following error: 

C:\Temp\File.dat contained an unexpected object.

I use the following code for deserialization:

CObListlist;

CFile in(csTempFilePath, CFile::modeRead);

CArchive ar(&in, CArchive::load);

list.Serialize(ar);

Anyone have idea of what is the issue here?

How to create transparent TreeView?

$
0
0

Hi

How to create transparent tree view like Windows Media Player?

I know ListView has a LVS_EX_TRANSPARENTBKGND and must processWM_PRINTCLIENT for it, but the tree view not has that style!

Environment: Win 10, VC++, MFC




a setup package is either missing or damaged

$
0
0

what am I doing????

When I install the vs2015, it always gives "a setup package is either missing or damaged"R

Not able to access protected enum variable in the VS2015

$
0
0

The below program is compiling well with the VS2010 without any error ,but when i am compiling same piece of code using vs2015 getting compile time error  stated that error C2248: 'Base::IDD': cannot access protected enumerator declared in class 'Base'

#include "stdafx.h"

#include<iostream>
using namespace std;
class Base
{
int i;
protected:
enum { IDD = 10 };
public:
void show()
{
cout << i;
}
Base()
{
i = 10;
}
};

class Derived : public Base
{
int k;
public:
void showDerived(int unDialog = Derived::IDD)
{
k = Derived::IDD;
}

};
int main()
{
    return 0;
}

I have read in some website  that this is problem with VS2015 compiler after install update 1 but in my case i  installed VS2015 and Update 3.

 

can any one please confirm whether this problem still persist in VS2015 update 3 pack (not able to access enum variable in the derived class)?

Using CMFCMaskedEdit Causes dialog to close

$
0
0

Hi there,

using Visual Studio 2010 SP1 and MFC I'm creating a CMFCPropertySheet with multiple CMFCPropertyPage. Since I need to use a masked input I dropped a MFC Masked edit control in my dialog template and set the following fields:

  • input template field to: "__.__";
  • mask to: "dD.DD";
  • valid chars: "0123456789."

then, in my implementation of DoDataExchange:

DDX_Text(pDX, IDC_ED_MASKEDEDIT1, m_dDoubleValue);

but, as soon as I run the Property Sheet it closes automatically. I also tried to put a default masked edit but nothing to do. A breakpoint in DoDataExchange is not reached. If I delete the dropped control, and obviously any code line relative to it, everything goes well.

In another project I use the same mask and it works but it's a CDialogEx not a CMFCPropertyPage, so I'm guessing that the problem might be in there.


IssamTP

How can we open a default mail client with an attachment in C++ ?

$
0
0

I want to open the default email client configured by the machine to open a mail with the fields To, Subject, Body filled and it has a zipped file as an attachment. 

We are coding in a dll file using C++. This function will be invoked from Java code. 

The major issue being faced is, the header file <MAPI.h> throws errors. 

Referring to the solution provided here: http://stackoverflow.com/questions/4819450/launch-default-email-client-to-open-a-send-email-window-with-a-pre-selected-fi 

How to do SAL on a static class variable?

$
0
0

Hi,

I'd like to add concurrency SAL annotation to my guarded static class variables, but I always get wiered error messages.

What I tried:

// declaration in .h file:
class CTrace
{
private:
static CCriticalSection m_csLogFile;
#ifdef _Interlocked_operand_
_Guarded_by_(CTrace::m_csLogFile)
#endif
static FILE * m_fpLogFile;
}

// definition in .cpp file:

CCriticalSection CTrace::m_csLogFile;

#ifdef _Interlocked_operand_
_Guarded_by_(CTrace::m_csLogFile)
#endif
FILE * CwwiTrace::m_fpLogFile = NULL;

With different tries of annotations I see error messages like:

C28285 Annotation syntax error in parameter
For function 'm_fpLogFile' 'base' syntax error in 'SAL_guarded_by(CTrace::m_csLogFile)' near 'CTrace::m_csLogFile'.

C26130 Missing _Requires_lock_held_ annotation
Missing annotation _Requires_lock_held_(CTrace::m_csLogFile) or _No_competing_thread_ at function '`dynamic initializer for 'CTrace::m_fpLogFile'. Otherwise it could be a race condition. Variable 'CTrace::m_fpLogFile' should be protected by lock CTrace::m_csLogFile.

It also seems to make a difference if the static Variabel is a object, e.g. CFile instead of FILE*.

I need to use the "#ifdef _Interlocked_operand_" since I also compile on older versions not supporting SAL.

What am I doing wrong? Do you have any suggestions?

Thanks,

Christian

Why calling IWebBrowser2::NavigateTo will change registry key "HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.html\UserChoice\Hash"

$
0
0

Hello,

My application uses IWebBrowser2 to render HTML/CSS UI. Unfortunately some anti-virus application will report security warning when it is launched. The message says "Default web browser setting is changed. Target is registry key 'HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.html\UserChoice\Hash'".

Anyone have idea how I can solve the issue?

The callstack are as below.

0	ntoskrnl.exe	SeQueryInformationToken + 0xa4c0	0xfffff8032b5235b0	C:\Windows\system32\ntoskrnl.exe
1	ntoskrnl.exe	RtlGetSaclSecurityDescriptor + 0x5ef0	0xfffff8032b5064a0	C:\Windows\system32\ntoskrnl.exe
2	ntoskrnl.exe	setjmpex + 0x3983	0xfffff8032b1c71a3	C:\Windows\system32\ntoskrnl.exe
3	ntdll.dll	ZwSetValueKey + 0x14	0x7ffca7605cd4	C:\Windows\System32\ntdll.dll
4	KernelBase.dll	RegSetValueExW + 0x363	0x7ffca3cf2683	C:\Windows\System32\KernelBase.dll
5	KernelBase.dll	RegSetValueExW + 0x141	0x7ffca3cf2461	C:\Windows\System32\KernelBase.dll
6	SHCore.dll	SHSetValueW + 0x9a	0x7ffca3c498ea	C:\Windows\System32\SHCore.dll
7	windows.storage.dll	SendNotificationsForLibraryItem + 0x20348	0x7ffca45f4048	C:\Windows\System32\windows.storage.dll
8	windows.storage.dll	SendNotificationsForLibraryItem + 0x1acf5	0x7ffca45ee9f5	C:\Windows\System32\windows.storage.dll
9	windows.storage.dll	DllMain + 0x147a3	0x7ffca43e5673	C:\Windows\System32\windows.storage.dll
10	windows.storage.dll	DllMain + 0x14e27	0x7ffca43e5cf7	C:\Windows\System32\windows.storage.dll
11	windows.storage.dll	DllMain + 0x123a9	0x7ffca43e3279	C:\Windows\System32\windows.storage.dll
12	windows.storage.dll	DllMain + 0x14c23	0x7ffca43e5af3	C:\Windows\System32\windows.storage.dll
13	windows.storage.dll	GetFindDataForPath + 0xf93	0x7ffca429bce3	C:\Windows\System32\windows.storage.dll
14	windows.storage.dll	GetFindDataForPath + 0xc45	0x7ffca429b995	C:\Windows\System32\windows.storage.dll
15	windows.storage.dll	CShellItem_CreateInstance + 0x4dc4	0x7ffca42552a4	C:\Windows\System32\windows.storage.dll
16	windows.storage.dll	CShellItem_CreateInstance + 0x4c69	0x7ffca4255149	C:\Windows\System32\windows.storage.dll
17	windows.storage.dll	SHParseDisplayName + 0x12877	0x7ffca4287097	C:\Windows\System32\windows.storage.dll
18	windows.storage.dll	SHParseDisplayName + 0x11cbe	0x7ffca42864de	C:\Windows\System32\windows.storage.dll
19	windows.storage.dll	Ordinal923 + 0x8f51	0x7ffca4262f01	C:\Windows\System32\windows.storage.dll
20	windows.storage.dll	Ordinal923 + 0x8282	0x7ffca4262232	C:\Windows\System32\windows.storage.dll
21	windows.storage.dll	CShellItem_CreateInstance + 0x2ecc	0x7ffca42533ac	C:\Windows\System32\windows.storage.dll
22	windows.storage.dll	CShellItem_CreateInstance + 0x5eb8	0x7ffca4256398	C:\Windows\System32\windows.storage.dll
23	windows.storage.dll	CShellItem_CreateInstance + 0x58be	0x7ffca4255d9e	C:\Windows\System32\windows.storage.dll
24	windows.storage.dll	SHBindToObject + 0x18680	0x7ffca42433d0	C:\Windows\System32\windows.storage.dll
25	windows.storage.dll	ILRemoveLastID + 0x9ee4	0x7ffca4224654	C:\Windows\System32\windows.storage.dll
26	windows.storage.dll	ILRemoveLastID + 0x984e	0x7ffca4223fbe	C:\Windows\System32\windows.storage.dll
27	shell32.dll	SHBindToObject + 0x88	0x7ffca4ff3858	C:\Windows\System32\shell32.dll
28	ieframe.dll	Ordinal222 + 0x3fe76	0x7ffc87d0d9e6	C:\Windows\System32\ieframe.dll
29	ieframe.dll	Ordinal222 + 0x3c9ac	0x7ffc87d0a51c	C:\Windows\System32\ieframe.dll
30	ieframe.dll	Ordinal150 + 0x70354	0x7ffc87ee8444	C:\Windows\System32\ieframe.dll
31	ieframe.dll	Ordinal222 + 0x3db92	0x7ffc87d0b702	C:\Windows\System32\ieframe.dll
32	ieframe.dll	Ordinal222 + 0x3a9dd	0x7ffc87d0854d	C:\Windows\System32\ieframe.dll
33	ieframe.dll	Ordinal150 + 0x3ac6f	0x7ffc87eb2d5f	C:\Windows\System32\ieframe.dll
34	ieframe.dll	Ordinal150 + 0x3ab82	0x7ffc87eb2c72	C:\Windows\System32\ieframe.dll
35	ieframe.dll	Ordinal101 + 0x19380	0x7ffc87cc1d10	C:\Windows\System32\ieframe.dll
36	user32.dll	DispatchMessageW + 0x689	0x7ffca6c11169	C:\Windows\System32\user32.dll
37	user32.dll	SendMessageW + 0x395	0x7ffca6c108f5	C:\Windows\System32\user32.dll
38	user32.dll	SendMessageW + 0xfb	0x7ffca6c1065b	C:\Windows\System32\user32.dll
39	ieframe.dll	Ordinal150 + 0x6fce8	0x7ffc87ee7dd8	C:\Windows\System32\ieframe.dll
40	ieframe.dll	Ordinal150 + 0x6ac10	0x7ffc87ee2d00	C:\Windows\System32\ieframe.dll
41	ieframe.dll	Ordinal150 + 0x34e57	0x7ffc87eacf47	C:\Windows\System32\ieframe.dll
42	ieframe.dll	Ordinal150 + 0x6ac82	0x7ffc87ee2d72	C:\Windows\System32\ieframe.dll
43	ieframe.dll	HlinkFindFrame + 0x582d	0x7ffc87e533bd	C:\Windows\System32\ieframe.dll
44	ieframe.dll	HlinkFindFrame + 0x75b0	0x7ffc87e55140	C:\Windows\System32\ieframe.dll
45	ieframe.dll	HlinkFindFrame + 0x37d6	0x7ffc87e51366	C:\Windows\System32\ieframe.dll
46	ieframe.dll	Ordinal150 + 0x37240	0x7ffc87eaf330	C:\Windows\System32\ieframe.dll
47	MyJSBridge.dll	EmbedBrowser::NavigateTo + 0x88	0x7ffc9f7549c8	...\MyJSBridge.dll
48	MyJSBridge.dll	jsbridgewindowsimpl::Initialize + 0x3c8	0x7ffc9f756868	...\MyJSBridge.dll
49	MyJSBridge.dll	jsbridge::Initialize + 0x1fe	0x7ffc9f7523ae	...\MyJSBridge.dll



Marshal Tu




Problem on Tooltip

$
0
0

Hi

I use TTM_TRACKACTIVATE and TTM_TRACKPOSITION to display the tool-tip. My problem is on hiding the tool when i do not want the tool displayed. I use following code but when using the Pop() method the tool does not appear on my window and when removing the Pop() method the tool-tip will remain on the window?!

// On WM_CREATE /////////////////////////////////////////////

if (!m_wndTip.Create(this, WS_POPUP | TTS_NOPREFIX | TTS_ALWAYSTIP | TTS_NOFADE | TTS_NOANIMATE))

{

return -1;

}

    if (m_wndTip.GetSafeHwnd())
    {
        ::SetWindowPos(m_wndTip.m_hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_SHOWWINDOW);

        m_wndTip.SetMaxTipWidth(200);

        TOOLINFO ti;
        ZeroMemory(&ti, sizeof(TOOLINFO));

        ti.cbSize = sizeof(TOOLINFO);
        ti.uFlags = TTF_TRACK | TTF_IDISHWND | TTF_ABSOLUTE;
        ti.hwnd = m_hWnd;
        ti.hinst = AfxGetInstanceHandle();
        ti.uId = (UINT_PTR)m_hWnd;
        ti.lpszText = LPSTR_TEXTCALLBACK;
        
        m_wndTip.SendMessage(TTM_ADDTOOL, 0, (LPARAM)&ti);

        m_wndTip.SendMessage(TTM_TRACKACTIVATE, TRUE, (LPARAM)&ti);
    }

// On WM_MOUSEMOVE //////////////////////////////////////////// if (bShow) { ClientToScreen(&point); m_wndTip.SendMessage(TTM_TRACKPOSITION, 0, MAKELONG(point.x + 15, point.y + 15)); } else { // m_wndTip.Pop(); // my problem is here! }









GetOpenFileName or CLSID_FileOpenDialog access violation, and strange solution

$
0
0
My question is very similar to this:
https://social.msdn.microsoft.com/Forums/vstudio/en-US/aca162b6-ebe3-49a6-83b6-338e71d706a0/access-violation-inside-of-clsidfileopendialog-com-object?forum=windowsuidevelopment

But instead of necroing an old post that already has a lot of irrelevant noise in it, I wanted to focus on my strange solution which I would like to find an explanation for.

To give some guidelines for reproduction: using VS2015, on Windows 7 Enterprise SP 1, I created a new project using the Win32 template, then selected Windows application, which created a simple window with a menu and a message loop in WinMain. Simply replacing the Exit menu event with the following code results in a crash with access violation exactly two minutes after closing the file open dialog:

switch (wmId)
{
case IDM_EXIT:
{
IFileOpenDialog* pfd;
HRESULT hr = CoCreateInstance(CLSID_FileOpenDialog, NULL, CLSCTX_INPROC_SERVER, IID_IFileOpenDialog, reinterpret_cast<void**>(&pfd));
pfd->Show(0);
pfd->Release();

I initialise COM in STA mode in WinMain like so:

CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE );

// Main message loop:
while (GetMessage(&msg, nullptr, 0, 0))
{
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}

CoUninitialize();

This happens on at least two different machines (with two different daily users) that I have tested. Just before crashing, most often (but not always), one or multiple instances of this message appear in the debug output:

Exception thrown at 0x76BDC54F (KernelBase.dll) in FileDialogTest.exe: 0x80010108: The object invoked has disconnected from its clients.

Now, the provided "solution" in the other thread is to disable the offending Shell extension, that seems to be doing something and crashing on cleanup after 2 minutes. However, what bothers me about this solution is the fact that many other applications seem to work just fine with all the shell extensions enabled, so what is the difference? If it works for other apps, it should work for mine, right. Also, I don't want to force the users of my app to hunt down and disable shell extensions on their systems.

Firstly, I am still not sure if the exception is directly related to the access violation or whether it is just a coincidence. The common explanation for the 0x80010108 error is that the main STA thread is missing the message pump. But as you can see, that is clearly not the case, since WinMain continues to pump messages well after the dialog is closed, so I don't understand why the 0x80010108 error is ever reported in the first place.

Secondly, I found out an alternative solution which works on both tested machines, which is to enable COM in a multithreaded mode, but according to all documentation that should be wrong for doing any kind work that involves UI. If I pass COINIT_MULTITHREADED to CoInitializeEx, I never ever get the above exception reported and I never get a crash (well, since the crash is not 100% reproducible I cannot say for sure, but I've tried to open the dialog and then wait 2 minutes up to 10 times in a row, whereas in a STA mode, it would consistently take at most 3 attempts for it to crash). What is it with the multithreaded model, that somehow handles the offending Shell extension gracefully? I feel that if I understood that, I could implement the same graceful handling while retaining the STA mode on the main thread. This is important, because I also want to support Drag&Drop which requires my main thread to call OleInitialize, and that sets up an STA, not an MTA.

The documentation here https://support.microsoft.com/en-us/kb/150777 says that if a MTA attempts to create a COM object with an "Apartment" ThreadedModel (which I'm assuming CLSID_FileOpenDialog is), it will instead be created on a new STA that the COM model "spins up". I still don't understand what exactly "spins up" here refers to. Does it run a new thread that calls CoInitializeEx with STA mode?

So to dig deeper into this I tried calling OleInitialize on the main thread, then in the menu message handler creating a new thread (using CreateThread) and in it initialise COM, show the dialog, uninitialise COM, and return. The access violation still occurred, regardless of the COM threading model used in the new thread. So, considering that multi-threaded model fixed the main-thread case for me, I thought maybe it had something to do with that fact that my MTA thread calls CoUninitialise before the 2 minute cleanup happens, so I removed the CoUninitialize call from the thread function. The access violation still occurred.

The next thing I tried was, to make my dialog thread CoInitialize in MTA mode, and run a message loop after showing the dialog, essentially making the thread never exit. Lo and behold, no access violation. However, I then put a breakpoint in the message loop and realised that the thread was actually never getting any messages (kind of expected, given the docs say there is no message pump required in MTA). So I realised, that maybe it's all about the MTA thread never exiting. So I created a semaphore and replaced the message loop in the MTA thread with WaitForSingleObject(mySemaphore, INFINITE) and that worked just as well, no access violation. It seems that when the thread exsits, the COM system detects that and does some kind of cleanup, even though CoUninitialise was never called by the thread, which again makes some shell extensions run into a wall at the 2 minute mark.

So there you have it: to avoid access violation you need to show the file dialog from an MTA thread that never exits. That could be the main thread, or another thread. Obviously, in my naive setup above, I ended up with multiple zombie threads stuck waiting on the semaphore, so my final solution is to reuse the same thread by signaling the semaphore, which the thread waits for in a loop. I use a critical section to transfer info to and back from the file dialog thread.

I would still like to get an explanation for why all this works the way it does, and ultimately, I would like to figure out if there's another, more sane way to handle the access violation, without requiring the app users to disable shell extensions.


DLL Calls from current Directory by advapi32.dll

$
0
0

I have build an executable(application .exe) using below code:

int main() { SetDefaultDllDirectories(LOAD_LIBRARY_SEARCH_SYSTEM32);

return 0; }

IDE Used: Visual Studio Professional 2015

On invoking this exe, I could see it looks for cryptbase.dll and bcryptprimitives.dll in the directory where executable is placed. (these are implicit system dll calls)
As cryptbase.dll and bcryptprimitives.dll are system dlls and expected to be present in system32 I do not want my executable to look for it in current directory and be vulnerable to DLL Hijack kind of attack..

On analyzing the dependency further I could see advapi32.dll is the one which is making calls to cryptbase.dll and bcryptprimitives.dll.

Though advapi32.dll loads itself from system32 directory but invokes cryptbase.dll and bcryptprimitives.dll from current directory.

If I delay load advapi32.dll the problem is resolved, but I am not sure if that is the right approach to handle this and whether this could lead to any other issues?

What is the recommended way to avoid loading of cryptbase.dll and bcryptprimitives.dll from current directory?

Thanks,
San



/AI switch or LIBPATH

$
0
0

Dear VS doctors out there!

I am a newbie on both VS & C++.   I am developing key testing programs for such as class, structure, array, function and etc.

In doing so, I have encountered handle(^), member access operator(->) and gcnew.   The sample program script led to

program error c1107.  Description on the possible solution is said to be related to /AI switch or LIBPATH. I read all notes

related to those keywords here in the Forum, MSDN description, and I have concluded the solution for this error to be beyond my ability, though I am reasonably good at HTML, PHP, VBA, COBOL, and MYSQL.   I am at a loss.  Something like this important matter deserves better explanation and sample solutions.     I would appreciate that someone helps me.

Also, I owe Sera Yu big thanks for the reply I submitted the question for last June.    Then, I did not know how to get back to the person who tried to help me.   My sincere apology to Sera Yu.

Chan B. Oh


cbo

Exception thrown at 0x771AB2D5 (ntdll.dll) in Magic.exe: 0xC0000005: Access violation reading location 0x06FFFFFF.

$
0
0

Hello,

I'm working with a Visual Studio 2015 C++ program converted from a VS 6.0 C++ program.

When I run  the program it gives this error:

Exception thrown at 0x771AB2D5 (ntdll.dll) in Magic.exe: 0xC0000005: Access violation reading location 0x06FFFFFF.

If there is a handler for this exception, the program may be safely continued.



I use the debugger to find out where it is blowing up.  It is stopping inside this for loop that is highlighted here:

template<class TYPE, class ARG_TYPE>
void CArray<TYPE, ARG_TYPE>::SetSize(INT_PTR nNewSize, INT_PTR nGrowBy)
{
	ASSERT_VALID(this);
	ASSERT(nNewSize >= 0);

	if(nNewSize < 0 )
		AfxThrowInvalidArgException();

	if (nGrowBy >= 0)
		m_nGrowBy = nGrowBy;  // set new size

	if (nNewSize == 0)
	{
		// shrink to nothing
		if (m_pData != NULL)
		{
			for( int i = 0; i < m_nSize; i++ )
				(m_pData + i)->~TYPE();
			delete[] (BYTE*)m_pData;
			m_pData = NULL;
		}
		m_nSize = m_nMaxSize = 0;
	}
	else if (m_pData == NULL)
	{
		// create buffer big enough to hold number of requested elements or
		// m_nGrowBy elements, whichever is larger.
#ifdef SIZE_T_MAX
		ASSERT(nNewSize <= SIZE_T_MAX/sizeof(TYPE));    // no overflow
#endif
		size_t nAllocSize = __max(nNewSize, m_nGrowBy);
		m_pData = (TYPE*) new BYTE[(size_t)nAllocSize * sizeof(TYPE)];
		memset((void*)m_pData, 0, (size_t)nAllocSize * sizeof(TYPE));
		for( int i = 0; i < nNewSize; i++ )
#pragma push_macro("new")
#undef new
			::new( (void*)( m_pData + i ) ) TYPE;
#pragma pop_macro("new")
		m_nSize = nNewSize;
		m_nMaxSize = nAllocSize;
	}
	else if (nNewSize <= m_nMaxSize)
	{
		// it fits
		if (nNewSize > m_nSize)
		{
			// initialize the new elements
			memset((void*)(m_pData + m_nSize), 0, (size_t)(nNewSize-m_nSize) * sizeof(TYPE));
			for( int i = 0; i < nNewSize-m_nSize; i++ )
#pragma push_macro("new")
#undef new
				::new( (void*)( m_pData + m_nSize + i ) ) TYPE;
#pragma pop_macro("new")
		}
		else if (m_nSize > nNewSize)
		{
			// destroy the old elementsfor( int i = 0; i < m_nSize-nNewSize; i++ )
				(m_pData + nNewSize + i)->~TYPE();		}
		m_nSize = nNewSize;
	}
	else
	{
		// otherwise, grow array
		nGrowBy = m_nGrowBy;
		if (nGrowBy == 0)
		{
			// heuristically determine growth when nGrowBy == 0
			//  (this avoids heap fragmentation in many situations)
			nGrowBy = m_nSize / 8;
			nGrowBy = (nGrowBy < 4) ? 4 : ((nGrowBy > 1024) ? 1024 : nGrowBy);
		}
		INT_PTR nNewMax;
		if (nNewSize < m_nMaxSize + nGrowBy)
			nNewMax = m_nMaxSize + nGrowBy;  // granularity
		else
			nNewMax = nNewSize;  // no slush

		ASSERT(nNewMax >= m_nMaxSize);  // no wrap around

		if(nNewMax  < m_nMaxSize)
			AfxThrowInvalidArgException();

#ifdef SIZE_T_MAX
		ASSERT(nNewMax <= SIZE_T_MAX/sizeof(TYPE)); // no overflow
#endif
		TYPE* pNewData = (TYPE*) new BYTE[(size_t)nNewMax * sizeof(TYPE)];

		// copy new data from old
		::ATL::Checked::memcpy_s(pNewData, (size_t)nNewMax * sizeof(TYPE),
			m_pData, (size_t)m_nSize * sizeof(TYPE));

		// construct remaining elements
		ASSERT(nNewSize > m_nSize);
		memset((void*)(pNewData + m_nSize), 0, (size_t)(nNewSize-m_nSize) * sizeof(TYPE));
		for( int i = 0; i < nNewSize-m_nSize; i++ )
#pragma push_macro("new")
#undef new
			::new( (void*)( pNewData + m_nSize + i ) ) TYPE;
#pragma pop_macro("new")

		// get rid of old stuff (note: no destructors called)
		delete[] (BYTE*)m_pData;
		m_pData = pNewData;
		m_nSize = nNewSize;
		m_nMaxSize = nNewMax;
	}
}


If I stop it just before it blows up, "m_pData" contains: "m_aCnd = 0x0162637c {{m_nField=0 '\0' m_nOperation=13 '\r' m_sText=<Error reading characters of string.> ...}, ...}m_sMailBox = <Error reading characters of string.>"

which does not seem readable.

It looks like m_pData is initialized earlier in the method with this line:

m_pData = (TYPE*) new BYTE[(size_t)nAllocSize * sizeof(TYPE)];


Any help that anyone can provide to help resolve this error 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.


Can anybody share a folder contents

$
0
0

Can anybody share a folder contents in zip file with me.

C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\ItemTemplates\VC\

I have missing Visual C++ default template. It shows No items found when i ADD New Item in source files in the project.

Viewing all 15302 articles
Browse latest View live


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