I was looking at using SetDlgItemInt and out of curiosity I changed it to SetDlgItemDouble to see if this was also a function.
SetDlgItemDouble has been recognised as a function and when I hover over it, it displays BOOL SetDlgItemDouble(HWND hDlg, int id, double d) but when I go to compile it gives me the error: error C3861: 'SetDlgItemDouble': identifier not found, even with argument-dependent lookup.
I've googled the term SetDlgItemDouble and it gives me a few links mainly in a far east language but nothing directly with MSDN and also searching this site nothing comes back.
So is it a function? If so, how do I use it with visual c++ 2003?
SetDlgItemDouble is not a standard C++ function: i.e. a standards compliant C++ compiler is not required to implement it.
But there's nothing stopping you from implementing it. Or a 3rd party library for that matter.
Your IDE is probably configured to think that the function exists, even if you don't have an explicit #include to the relevant file. Visual Studio does tend to do this (especially for standard C++ library functions that you haven't necessarily #included), in order to attempt to be helpful.
SetDlgItemDouble is not avaialble in MFC or win32. You can try using SetDlgItemInt (or) SetDlgItemText in visual c++. If the intention is to display a double value in any Dialog control, you can use SetDlgItemText and display that value as a string in your Dialog.
Related
I'm running into a very strange problem trying to compile and use a windows runtime component within an UWP application (VS2017 community 15.9.13 with NetCore.UniversalWindowsPlatform 6.2.8, compiled without /clr but with /ZW).
It is basically something like the Grayscaletransform. The runtime component is actually working as expected, now I wanted to remove some unused code. However, as soon as I remove it from a particular file and recompile, it indeed compiles, links, but the DLL does not load any more.
Here's some example code that I have to put in:
ref class DummyU sealed
{
public:
DummyU() {}
};
DummyU^ CreateDummyU()
{
return ref new DummyU();
}
The code just makes it work, although it is a) not referenced at all and b) does not do anything useful.
The result of removing it:
Exception thrown at 0x0EFF322F (vccorlib140d_app.dll) in TestAppUWP.exe: 0xC0000005: Access violation reading location 0x00000000.
in
STDAPI DllGetActivationFactory(_In_ HSTRING activatibleClassId, _Deref_out_ IActivationFactory** ppFactory)
{
return Platform::Details::GetActivationFactory(Microsoft::WRL::Details::ModuleBase::module_, activatibleClassId, ppFactory);
}
function in dllexports.cpp which is part of VS. The module_ becomes NULL.
Does anyone have an idea if there are any known bugs with respect to the windows runtime not being initialized/used properly if there is no explicit instantiation of a ref class in a file?
EDIT 1:
Here's the link to the full source code:
What's happening here is that you're mixing modes a bit. Since you've compiled your C++ code with the /CX flag, you've told the compiler to enable winrt extensions to produce a WinRT DLL. In practice though, none of your code is actually using the CX extensions to implement classes. You're using WRL and standards C++. The compiler looks at the DLL, finds no CX-style WinRT classes, and doesn't set up the module, accordingly.
This is basically an untested & unsupported case, since you've chosen to say that you want to expose ref classes by picking a UWP component library project type, but then didn't actually provide any ref classes. It happens that under the hood, /CX effectively uses WRL, so you can nudge it along and initialize the state to work correctly, but you're kinda hacking the implementation details of the system.
There are two options I would recommend, either works: just make the project a non-CX Win32 DLL and init the module as described above. Or, better yet, flip over to C++ /WinRT, which will give you better support for the WinRT types than /CX and allow you to more easily mix in the classic COM types in your implementation. You can get started by just turning off the /CX flag in the compiler switches, then start updating the code accordingly.
Ben
You might have wrong .winmd file for your component. WinRT components made in C++ produce two outputs, dll and winmd. Both must match. It's possible you have them from different builds.
Another possible reason is error in manifest. The manifest of the app must include all referenced runtime components.
BTW, for native DLLs written in classic C++ and exposing C API, deployment is simpler, you include a DLL in the package and they just work, with [DllImport] if you're consuming them from C#.
Update: You can replace that ref class with the following code, works on my PC.
struct ModuleStaticInitialize
{
ModuleStaticInitialize()
{
Microsoft::WRL::Module<Microsoft::WRL::InProc>::GetModule();
}
};
static ModuleStaticInitialize s_moduleInit;
Probably a bug in Microsoft's runtime somewhere.
I'm using an external library (Qpid Proton C++) in my Visual Studio project.
The API includes a method like:
container::connect(const std::string &url) {...}
I call it in my code this way:
container.connect("127.0.0.1");
but when debugging, stepping into the library's function, the string gets interpreted in the wrong way, with a size of some millions chars, and unintelligible content.
What could be the cause for this?
You need to put the breakpoint inside the function and not at the function declaration level, where the variable exists but is not yet initialized.
Just in case someone runs into a similar problem, as Alan Birtles was mentioning in his comment, one possible cause is having the library and your code using different C++ runtimes, and that turned out to be the case this time.
In general, as stated in this page from Visual C++ documentation,
If you're using CRT (C Runtime) or STL (Standard Template Library) types, don't pass them between binaries (including DLLs) that were compiled by using different versions of the compiler.
which is exactly what was going on.
I found that documentation on MSVC's _doserrno global variable is very "sparse", so to say. Its existence is mentioned in the documentation for errno, the Standard C global variable for error codes. At the same time _doserrno seems to be an MSVC extension. The documentation mentions that it may provide additional information on I/O errors, but it also says most functions do not set it.
But what functions do set it? There doesn't seem to be a list for this, or did I miss anything? In the documentation for individual functions I also do not see any mention like "this function does [not] set _doserrno". So how do I know whether a function does set it or not? Very confusing, isn't it?
Furthermore, the documentation doesn't say a word about how the values of _doserrno have to be interpreted. If figured, from my own testing, that it's just the Win32 Error Code passed through from the Win32 API to the C API. But is this always the case? And how to convert _doserrno to string?
(I know I could use FormatMessage() directly from Win32 API to get a string from Win32 Error Codes. But reverting to the Win32 API totally contradicts the purose of having _doserrno in the C API!)
Regards,MuldeR
I think it’s impossible to do what you want.
If you want to stick to portable C functions for IO, you won’t get sensible error codes or messages: neither C nor C++ standard library expose that stuff.
And if you want good error messages on Windows, you have to use Win32 API instead of portable C functions. BTW, there’re good OO wrappers above that, e.g. see CAtlFile for files.
Just for completeness since I just looked into this:
Look at the mapping in
C:\Program Files (x86)\Windows Kits\10\Source<SDKver>\ucrt\misc\errno.cpp
struct errentry
{
unsigned long oscode; // OS return value
int errnocode; // System V error code
};
These are the only mappings used between CRT error codes and OS error codes. Not all CRT error codes are mapped and just a fraction of the OS error codes. To get more detail and probably the real error you need to use the Windows SDK.
I have been writing Java for a long time using Eclipse, now trying to switch to C++ in Visual Studio. From Eclipse/Java I know such auto-complete features: I write
bar = Foo.valueOf(x);
bar.doSomething(y, z);
and Eclipse offers me both to import whatever Foo I might mean, and declare bar as local variable, field, or parameter. Or create the function doSomething() with the appropriate signature, auto-adding missing imports to Foo. I am missing a corresponding feature on Visual Studio 2015, which does for example
add the corresponding #include and #pragma comment(lib, statements,
add these statements in a clear order, so that they work as expected (something like organize imports),
add namespace statements
declare variables, fields, and parameters on click/keypress
create function bodies, adding the corresponding foreward declarations to the respective header files, adding missing includes required by the declaration
…
The only things that I found so far is the “add class” dialog. When writing an unknown function name, right clicking and choosing “quick actions and refactorings” → Create declaration / definition, a window opens with the text
int main(int argc, char * argv[]);
but it does not create a definition for that function.
Are there some better “save me typing work” functions available in Visual Studio 15, and if yes, how can I benefit from them? Is there another way I could go, such as writing the C++ program (Windows API) in an other IDE (are there any for Winapi C++ which do better?)
Resharper by JetBrains does what you are asking for more or less. It will notice an error in your code, whether it being that something wasn't fully initialized, or something that you needed to include, or a host of other things.
It is not free though, but you can try it on a 30 day trial.
I don't know of an IDE that supports winapi functions like you're asking though. I think you'll just have to pick your favorite IDE and get used to it.
I am trying to convert an Adobe CS4 based plugin to CS5. This project has never been mine, this is the first time that i am seeing it.
When I compile the source with what i was given, I get errors like: Does not name a type
Example:
SPAPI SPErr SPBasicAcquireSuite( const char *name, int64 version, const void **suite );
I get that:
SPErr does not name a type
I dont see any classes with SPErr being defined, but I doubt that Adobe has left this out of the SDK.
I am using the PS_CS5_SDK_3 SDK
I do not have the possibility to be specific because, of course, I do not have the code. Typically this problem occurs when a type, a class, is not correctly compiled by compiler... meaning that it cannot find it and asks: "what is this?". See macros, or better inspect your code in your hpp files... Probably when porting to CS5 some types have been removed or some...