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

DLL only working with Windows SDK installed

$
0
0

Hey,

I made a DLL (in C++) and would like to use it in Alaska (XBase++). I can not load the DLL if Windows SDK is not installed. (Other DLLs are loading correctly)

The DLL itself is just importing another DLL and exporting some functions. (Because you can't load .NET DLLs in Alaska directly)

Is there a way to get around installing Windows SDK?

Here's some Code:

dll.h:

__declspec(dllimport) int test(LPSTR cID);

some more...

dll.cpp

__declspec(dllexport) int test(LPSTR cID)
	{
		try {
			String ^S1 = gcnew System::String(cID);
			return CosCom::Diverse::test(S1);
		}
		catch (Exception^) {
			return 0;
		}
	}


Please tell me if you need additional information.

Thanks,

André.





How can I show the thousands separator at UWP app?

$
0
0

Hello,

I'm developing a simple calculator app to study UWP and c++/cx.

my intention was to show the result of arithmetic operations like this:

"1234 + 5678 = 6,912" 

to fulfill my intention, I designed one textblock and one button(its content is "=") so I can press button to show the result in the textblock. related code is following:

void PracCalc::MainPage::EqualsButton_Click(Platform::Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ e)
{
	String^ readb = txtOutput->Text;
	std::wstring str = readb->Data();
	txtOutput->Text = readb + "=" + EvalExpression(str).ToString();
}

The Problem is How can I format (EvalExpression(str).ToString()) to show thousands separator.

if anyone pick error in this code or show the solution, I'd be very appreciate.

thx,

The fastest way to draw 2D via directly setting pixel values?

$
0
0

Below is an example of the code I use in my Win32 project:

HBITMAP _hbDIB; uc *_bitDIB; HDC _hdc, _hdcMem; HWND _cWnd;

...

void SetDIB(HWND hwnd, int width, int height, unsigned char **p, HBITMAP *hBmp) { BITMAPINFO bmi; bmi.bmiHeader.biSize = sizeof(BITMAPINFO); bmi.bmiHeader.biWidth = width; bmi.bmiHeader.biHeight = -height; bmi.bmiHeader.biPlanes = 1; bmi.bmiHeader.biBitCount = 32; bmi.bmiHeader.biCompression = BI_RGB; bmi.bmiHeader.biSizeImage = 0; bmi.bmiHeader.biXPelsPerMeter = 0; bmi.bmiHeader.biYPelsPerMeter = 0; bmi.bmiHeader.biClrUsed = 0; bmi.bmiHeader.biClrImportant = 0; bmi.bmiColors[0].rgbBlue = 0; bmi.bmiColors[0].rgbGreen = 0; bmi.bmiColors[0].rgbRed = 0; bmi.bmiColors[0].rgbReserved = 0; HDC hdc = GetDC(hwnd); *hBmp = CreateDIBSection(hdc, &bmi, DIB_RGB_COLORS, (void**)p, NULL, 0); ReleaseDC(hwnd, hdc); }

...

void Draw() { ui xp, yp; while(cond) { xp = RND; yp = RND; for(ui i = 0; i < 200; i++) for(ui j = 0; j < 250; j++) *((int*)_bitDIB + (xp+i) + (yp+j) * CWW) = 0x00FF0000 + 0x00000001 * j + 0x00000100 * i; BitBlt(_hdc, 0, 0, CWW, CWH, _hdcMem, 0, 0, SRCCOPY); } }

// main

_cWnd = CreateWindow(...);

... SetDIB(_cWnd, CWW, CWH, &_bitDIB, &_hbDIB); _hdc = GetDC(_cWnd); _hdcMem = CreateCompatibleDC(_hdc); SelectObject(_hdcMem, _hbDIB); CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)Draw, NULL, 0, NULL);

My questions are:

1. Is this the fastest way to draw 2D via directly setting pixel values?

2. Does it use a built-in Intel Graphics chip or my actual video card?

3. If it doesn't use the video card, how can I draw using it ( I have NVIDIA)?

Thank you!

Why Can't I Set Breakpoints In One Module?

$
0
0

Hi Folks:

   Developing on Windows 10 Pro, VS Community 2017, all C++.

   For some reason there is one module that won't let me set breakpoints.  I can set the breakpoints before I start debugging and everything looks fine, the breakpoints are marked by nice solid red circles. 

   Once I start the debug, the breakpoint circles are there, but now they're hollow. 

   There are dozens of other C++ modules in this project and many projects in the application.  Breakpoints seem to work fine for everything else I've tried. 

   Suggestions?

Thanks
Larry


How to find the active user in windows service written in c++

$
0
0

I have created a service in c++. I need to find out the  active user in service(No need in the terminal server)

Is there is any possible way to find out the active user? please help.

C2440 error in xmemory line 881 using VS 2017

$
0
0

Hi ,

while compiling an application getting C2440 error in xmemory line 881 using VS 2017 . 

error description is "initializing": cannot convert from std::pair <const _Kty , _Ty> to _Objty

How to use MSFT_NetQosFlowControlSettingData class for specific adapter

$
0
0

Hi,

I`m trying to get NetQosFLowControl information for specific adapter using using C++/C#. 

I understand that I need to interact with MSFT_NetQosFlowControlSettingData class, but how I could get NetQosFLowControl information for specific adapter (-InterfaceAlias parameter)?
When I run PowerShell command "Get-NetQosFlowControl -InterfaceAlias "Ethernet 4"" what WMI query PowerShell does? Which WMI Objects/Methods/Properties does it access?

By enumerating properties and methods of MSFT_NetQosFlowControlSettingData class I found that it has "PolicySet" property and method "SwitchPolicySet" which takes three parameters: InterfaceAlias, InterfaceIndex, PolicySet. Those properties and method are undocumented and I don't know how to use them.

I think it could be related to the answer, but I don`t know exactly how.

Best Regards,
Alexander

win7 two display : layered window display error in assist-display

$
0
0

My application has a layered window.

1.My compute's os is win7, has two display, and use win7 basic theme.

2.I open my application. I drag this application to assist-display.

3.I open outlook application. I drag outlook to assist-display. I put outlook on my application.

And then there's such a phenomenon. When you click outlook or hover and move on outlook, the outlook will paint error content.

code : https://github.com/kniefliu/LayeredWindowDemo


Migrate from VS2015 to VS2017

$
0
0

In VS2015 I have a simple function to check if current system is MBCS and what is the Code Page.

 

   _locale_t loc = _create_locale (LC_CTYPE, pszName);
    if (loc != NULL)
    {
        gbl_isMBCS = loc->locinfo->mb_cur_max > 1;
        gbl_dCP = loc->locinfo->lc_codepage;
        _free_locale (loc);
    }

This code does not compile anymore under VS2017 SDK  10.0.15063.0

I'm getting an error "pointer to incomplete class type is not allowed" (refer the "loc" variable"

Any information about how to migrate the code?  I could not find any information.


Yigal Spinner


Windows Portable Device problem :) please HELP :)

$
0
0

Hello, I have a small problem with WPD. I have Canon PowerShot S60 connected to PC via USB. I am trying to take a picture using WPD in C#,  but there is some suspicious problem. The complette (and simple) source code is listed below.  If I use

this line: properties.GetValues("DEVICE", keys, out values);  everything is ok, but if I comment it out, the camera is NOT capable to take an image. The line  pd.SendCommand(0, par, out res);  is passed without error, but the image is not  taken. Can someone from WPD team can help where is the problem ? By the way how can I read error messages from pd.SendCommand(0, par, out res); ??

Many thanks

Jerry

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using PortableDeviceApiLib;
using PortableDeviceTypesLib;
using System.Diagnostics;
using System.IO;
using System.Runtime.InteropServices;
using System.Threading;

namespace PD
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("begin");
            PDProgram.DoWork();

        }// static void Main

    }// class Program
    
    public class PDProgram //: IDisposable
    {
       

        public static void DoWork()
        {


            var m = new PortableDeviceApiLib.PortableDeviceManager();

            m.RefreshDeviceList();


            uint count = 1;
            m.GetDevices(null, ref count);
            string[] ids = new string[count];
            m.GetDevices(ref ids[0], ref count);

            Console.WriteLine("Device: {0}, num devs: {1}", ids[0], count);
            Console.WriteLine();

            PortableDeviceApiLib.PortableDevice pd = new PortableDevice();

            var pdv = (PortableDeviceTypesLib.IPortableDeviceValues)new PortableDeviceValues();


            pd.Open(ids[0], (PortableDeviceApiLib.IPortableDeviceValues)pdv);

            IPortableDeviceContent content;
            IPortableDeviceProperties properties;
            pd.Content(out content);
            content.Properties(out properties);
            
                      
            //this is the mysterious part
            PortableDeviceApiLib.IPortableDeviceKeyCollection keys;
            properties.GetSupportedProperties("DEVICE", out keys);
            PortableDeviceApiLib.IPortableDeviceValues values;
            properties.GetValues("DEVICE", keys, out values);  // HERE, THIS LINE IS SUSPICIOUS

            Thread.Sleep(1000);

            //
            var par = (PortableDeviceApiLib.IPortableDeviceValues)new PortableDeviceValues();
            PortableDeviceApiLib.IPortableDeviceValues res;

            // WPD_PROPERTY_COMMON_COMMAND_CATEGORY
            PortableDeviceApiLib._tagpropertykey WPD_PROPERTY_COMMON_COMMAND_CATEGORY = new PortableDeviceApiLib._tagpropertykey() { fmtid = new Guid(0xF0422A9C, 0x5DC8, 0x4440, 0xB5, 0xBD, 0x5D, 0xF2, 0x88, 0x35, 0x65, 0x8A), pid = 1001 };
            // WPD_COMMAND_STILL_IMAGE_CAPTURE_INITIATE
            PortableDeviceApiLib._tagpropertykey WPD_COMMAND_STILL_IMAGE_CAPTURE_INITIATE = new PortableDeviceApiLib._tagpropertykey() { fmtid = new Guid(0x4FCD6982, 0x22A2, 0x4B05, 0xA4, 0x8B, 0x62, 0xD3, 0x8B, 0xF2, 0x7B, 0x32), pid = 2 };
            // WPD_PROPERTY_COMMON_COMMAND_I
            PortableDeviceApiLib._tagpropertykey WPD_PROPERTY_COMMON_COMMAND_ID = new PortableDeviceApiLib._tagpropertykey() { fmtid = new Guid(0xF0422A9C, 0x5DC8, 0x4440, 0xB5, 0xBD, 0x5D, 0xF2, 0x88, 0x35, 0x65, 0x8A), pid = 1002 };

            //
            par.SetGuidValue(WPD_PROPERTY_COMMON_COMMAND_CATEGORY, WPD_COMMAND_STILL_IMAGE_CAPTURE_INITIATE.fmtid);
            par.SetUnsignedIntegerValue(WPD_PROPERTY_COMMON_COMMAND_ID, WPD_COMMAND_STILL_IMAGE_CAPTURE_INITIATE.pid);

            //
            pd.SendCommand(0, par, out res);

            uint pcelt = 0;
            res.GetCount(ref pcelt);

            Console.WriteLine("res: {0}", pcelt);
            Console.WriteLine("Picture taken ok / I hope so :)");
           
            Console.ReadLine();

            pd.Close();

        }// public void Connect()
        

    }// class PDProgram

}// namespace PD

How to change PolicySet parameter of MSFT_NetQosFlowControlSettingData instance using WMI and C++

$
0
0

Hi,

I`m trying to write analog of powershell command using C++ and WMI infrastructure

Set-NetQosFlowControl -Priority 3 -Enabled $true -InterfaceAlias "Ethernet 4"


The tricky part is the last parameter and how to set it

-InterfaceAlias "Ethernet 4"

I tried multiple approaches but none of them worked:

1) a) Enumerate on MSFT_NetQosFlowControlSettingData class instances
    b) Modify Enabled, InterfaceAlias, InterfaceIndex and PolicySet properties
    c) Apply changes

2) a) GetObject directly using \\.\ROOT\StandardCimv2:MSFT_NetQosFlowControlSettingData.InstanceID="Priority3" path
    b) Modify Enabled, InterfaceAlias, InterfaceIndex and PolicySet properties
    c) Apply changes

3) a) GetObject using MSFT_NetQosFlowControlSettingData 
      b) Spawn instance of this class      c)Modify Enabled, InterfaceAlias, InterfaceIndex and PolicySet properties      d) Apply changes

All function calls success, but as the result I get Priority 3 enalbed for Global PolicySet and not for AdapterSpecific PolicySet:

Get-NetQosFlowControl
Priority   Enabled    PolicySet        IfIndex IfAlias
--------   -------    ---------        ------- -------
0          False      Global
1          False      Global
2          False      Global
3          True       Global
4          False      Global
5          False      Global
6          False      Global
7          False      Global
Get-NetQosFlowControl -InterfaceAlias "Ethernet 4"


Priority   Enabled    PolicySet        IfIndex IfAlias
--------   -------    ---------        ------- -------
0          False      AdapterSpecific  16      Ethernet 4
1          False      AdapterSpecific  16      Ethernet 4
2          False      AdapterSpecific  16      Ethernet 4
3          False      AdapterSpecific  16      Ethernet 4
4          False      AdapterSpecific  16      Ethernet 4
5          False      AdapterSpecific  16      Ethernet 4
6          False      AdapterSpecific  16      Ethernet 4
7          False      AdapterSpecific  16      Ethernet 4


If I use powershell commands for configuration I get the expected result:

Set-NetQosFlowControl -Priority 3 -Enabled $true -InterfaceAlias "Ethernet 4"
Get-NetQosFlowControl

Priority   Enabled    PolicySet        IfIndex IfAlias
--------   -------    ---------        ------- -------
0          False      Global
1          False      Global
2          False      Global
3          False      Global
4          False      Global
5          False      Global
6          False      Global
7          False      Global

Get-NetQosFlowControl -InterfaceAlias "Ethernet 4"

Priority   Enabled    PolicySet        IfIndex IfAlias
--------   -------    ---------        ------- -------
0          False      AdapterSpecific  16      Ethernet 4
1          False      AdapterSpecific  16      Ethernet 4
2          False      AdapterSpecific  16      Ethernet 4
3          True       AdapterSpecific  16      Ethernet 4
4          False      AdapterSpecific  16      Ethernet 4
5          False      AdapterSpecific  16      Ethernet 4
6          False      AdapterSpecific  16      Ethernet 4
7          False      AdapterSpecific  16      Ethernet 4

Could someone help me, or advice some different approaches?

Thanks,
Alexander


How can I find the Active user (owner of current desktop window) ?

$
0
0

Hi All,

We are developing a Windows service application using Visual Studio 2012 (VC++). We need to find the 'Active UserName' and 'Session ID' for the Active User from this Windows Service (running as System account). How can we do this in VC++? Anyone, please help.

Active user means 'Owner of the current desktop window'.

Thanks in advance.

R-VR

Combobox with owner draw issue

$
0
0

I create my dropdown list combo box (derived from CComboBox) with 2 columns, so I do my owner draw.

The problem I encountered is that after the combo box is painted for first time, when I hover the mouse over the combo box, it will trigger many DrawItem events that will make the combo box flickering so much.  I override the OnEraseBkgnd event, but the problem is still there.  Is anyone has any idea?

Thanks,

Steve

stack - winsock

$
0
0
Is stack realized in winsock ? Where can i find explain ?

How does windows calculate the default CComboBox item height ?

$
0
0

I have a dialog with multiple drop down combo boxes and 2 of them are custom drawn ones.

We're transitioning to high DPI support and I need to make the custom combo boxes have proper heights throughout the app.

What I need right now is how to calculate the default padding around the item of a combo box.

Back in the days of 96 DPI a few pixels off were unnoticeable but as Win 8.1 & 10 support scaling those 1-2 px differences become an issue with higher scaling.

I've hacked around it by creating an empty ComboBox and using GetClientRect and GetItemHeight(-1) to calculate the height padding, which I then cache to a variable, but this isn't really a good solution.


exe has triggered a breakpoint in vc++ mfc

$
0
0

Hello All,
I'm developing my MFC application(name abc) in  VC++ (visual studio 2008)
When I click close button it gives
"abc.exe has triggered a breakpoint". and it will point to this code of line #undef _CrtDbgBreak

/* These methods don't need a separate
   wchar version. Hence they need to be compiled only once from
   the original file */

_CRTIMP void _cdecl _CrtDbgBreak(
    void
    )
{
    DebugBreak(); //cursor point to this line
} in dbgrptt.c

I am using some dll in my application through function pointer.

Please suggest.


How to detect an exception before it's been caught and processed by an application

$
0
0

I have a DLL that uses Java via the Java Native Interface.  My DLL creates a Java virtual machine, and then uses JNI to execute commands in Java.  This all works great.  The DLL is in a standard format that can be into numerous music applications.

Java, however, uses exceptions internally, but these exceptions are all caught and handled within the Java virtual machine.  For example, whenever the Java Virtual Machine is created, this exception appears in the output window:

Exception thrown at 0x00000250AB3D03B4 in Voltage Modular.exe: 0xC0000005: Access violation reading location 0x0000000000000000

This is perfectly normal.  The same thing happens on macOS, for example.  It's been well-documented that creating a Java Virtual Machine via JNI will cause this exception to be thrown.  The exception is caught somewhere inside of the Java virtual machine, and the exception never reaches my DLL or the main application.

Now, one of the music programs that is loading my .DLL is somehow seeing that an exception is being thrown, and is deciding that there is an error with my DLL.  I don't know how the program knows about these exceptions.  These Java exceptions do not trigger SetUnhandledExceptionFilter() or any CRT error-handling or signal-throwing functions.  They're thrown and caught deep within Java.  I can't find any sort of Windows hook to find out if a program is throwing an exception. 

Perhaps it's attaching a debugger of sorts?  If that's the case, can I prevent that in some way?  I want to stop the music program from detecting that these exceptions occur, but I can't figure out how it would do that in the first place -- otherwise I'd try to override this action by detecting it and handling it myself first!

I'd appreciate any advice.

Thanks,
Dan

Odd compiler errors with vccorlib.h header

$
0
0

Hello,

we're trying to build our project for Universal Windows Platform, we're using CMake to generate the project for VS 2017.

We're having trouble understanding the following compile errors:

vccorlib.h(1560): error C3946: 'T': typeid cannot be applied to this type

vccorlib.h(1561): error C3536: '__typeCode': cannot be used before it is initialized (compiling source file C:\Users\Public\main\Drawing\Examples\WinWUP\OdaUWPApp\OdaUWPApp\common\SuspensionManager.cpp)

vccorlib.h(1561): error C2664: 'Platform::Object ^Platform::Details::CreateValue(Platform::TypeCode,const void *)': cannot convert argument 1 from 'int' to 'Platform::TypeCode' (compiling source file C:\Users\Public\main\Drawing\Examples\WinWUP\OdaUWPApp\OdaUWPApp\common\SuspensionManager.cpp)

Can anyone clarify what exactly is wrong with our code or project? Perhaps there is something with vs 2017 not finding a correct sdk?

Regards.

How can i determine memory type of another process?

$
0
0

Hi everyone! Using WINapi functions like OpenProcess, VirtualQueryEx and ReadProcessMemory, i can get access to all virtual memory addresses of program, and find needed variables using huge loop. But how can i define which type this variable is? I mean, in address 0x12345678 variable 65, it might be simple 65int, or 65 unsigned long int, or might be a char uppercase 'A'.

How can i get to know such things, and how software like CheatEngine can define what type that memory possess. And where should i seek to get to know about such things?


The fastest way to draw 2D via directly setting pixel values?

$
0
0

Below is an example of the code I use in my Win32 project:

HBITMAP _hbDIB; uc *_bitDIB; HDC _hdc, _hdcMem; HWND _cWnd;

...

void SetDIB(HWND hwnd, int width, int height, unsigned char **p, HBITMAP *hBmp) { BITMAPINFO bmi; bmi.bmiHeader.biSize = sizeof(BITMAPINFO); bmi.bmiHeader.biWidth = width; bmi.bmiHeader.biHeight = -height; bmi.bmiHeader.biPlanes = 1; bmi.bmiHeader.biBitCount = 32; bmi.bmiHeader.biCompression = BI_RGB; bmi.bmiHeader.biSizeImage = 0; bmi.bmiHeader.biXPelsPerMeter = 0; bmi.bmiHeader.biYPelsPerMeter = 0; bmi.bmiHeader.biClrUsed = 0; bmi.bmiHeader.biClrImportant = 0; bmi.bmiColors[0].rgbBlue = 0; bmi.bmiColors[0].rgbGreen = 0; bmi.bmiColors[0].rgbRed = 0; bmi.bmiColors[0].rgbReserved = 0; HDC hdc = GetDC(hwnd); *hBmp = CreateDIBSection(hdc, &bmi, DIB_RGB_COLORS, (void**)p, NULL, 0); ReleaseDC(hwnd, hdc); }

...

void Draw() { ui xp, yp; while(cond) { xp = RND; yp = RND; for(ui i = 0; i < 200; i++) for(ui j = 0; j < 250; j++) *((int*)_bitDIB + (xp+i) + (yp+j) * CWW) = 0x00FF0000 + 0x00000001 * j + 0x00000100 * i; BitBlt(_hdc, 0, 0, CWW, CWH, _hdcMem, 0, 0, SRCCOPY); } }

// main

_cWnd = CreateWindow(...);

... SetDIB(_cWnd, CWW, CWH, &_bitDIB, &_hbDIB); _hdc = GetDC(_cWnd); _hdcMem = CreateCompatibleDC(_hdc); SelectObject(_hdcMem, _hbDIB); CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)Draw, NULL, 0, NULL);

My questions are:

1. Is this the fastest way to draw 2D via directly setting pixel values?

2. Does it use a built-in Intel Graphics chip or my actual video card?

3. If it doesn't use the video card, how can I draw using it ( I have NVIDIA)?

Thank you!

Viewing all 15302 articles
Browse latest View live


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