Class2 Bank::function(const Object& object, const std::string& string)
{
....
return objectClass2;
}
I have a function which initialize in async like:
auto fu = std::async(std::launch::async, &Class::function, this, object, string);
After
Class2 newObjectClass2 = fu.get();
And i have error
Severity Code Description Project File Line Source Suppression State
Error C2512 'Class2': no appropriate default constructor
available ConsoleApplication18 c:\program files (x86)\microsoft visual
studio 14.0\vc\include\future 263 Build
Without future, my programm works well, all tests are passed.
This problem exist only in VC++, but in other compiler run ok.
Related
I am trying to use
wchar_t wFilename[MAX_PATH];
mbstowcs(wFilename, szFileNAme, MAX_PATH);
D3DCompileFromFile(wFilename, NULL, D3D_COMPILE_STANDARD_FILE_INCLUDE, szEntryPoint, szShaderModel, dwShaderFlags, 0, ppBlobOut, &pErrorBlob);
to compile my shaders for DirectX 11 and I keep getting a file not found error on the shader file. It is in the same directory as the file that is making the above call.
What could I be missing?
Edit: I've tried adding the shader file to my project which required another shader file which I added as well. Doing this causes an error: 'main':entrypoint not found for file "FXC"
Is that your entire code? As is, you aren't checking the return value of mbstowcs. It could be invalid due to an error and the destination array could be ill-formed. Hence, the "file not found" error.
If you are compiling the shader in-code then you need to tell Visual Studio to not compile the shader as part of the build process. You can do this by excluding it via right-clicking on the file in the solution explorer then Properties > General > Exclude from build: Yes
You are getting the error because the main entry point of your function is not named main and that's the default that FXC looks for. You can change it in the same properties pane as before: Properties > HLSL Compiler > General > Entrypoint name.
But, since you are compiling in-code with custom entry points, you should disable build-step compiling, so changing the entrypoint name will have no effect.
First you have to make sure that visual studio is copying the file into the build directory (that the executable is being executed from).
The DXSample.h header uses this code to find the executables directory path at runtime
inline void GetAssetsPath(_Out_writes_(pathSize) WCHAR* path, UINT pathSize)
{
if (path == nullptr)
{
throw std::exception();
}
DWORD size = GetModuleFileName(nullptr, path, pathSize);
if (size == 0 || size == pathSize)
{
// Method failed or path was truncated.
throw std::exception();
}
WCHAR* lastSlash = wcsrchr(path, L'\\');
if (lastSlash)
{
*(lastSlash + 1) = L'\0';
}
}
Here are some fragments of it being use
std::wstring m_assetsPath;
WCHAR assetsPath[512];
GetAssetsPath(assetsPath, _countof(assetsPath));
m_assetsPath = assetsPath;
std::wstring DeviceResources::GetAssetFullPath(LPCWSTR assetName)
{
return m_assetsPath + assetName;
}
deviceResources.GetAssetFullPath(L"compute_shader.cso").c_str(),
'main':entrypoint not found for file "FXC"
You probably have not specified what kind of shader it is in visual studio properly.
Am trying to compile a very elementary JNI program. The Java code is :
public class Helloworld {
public static void main(String[] args) {
System.out.println("Hello World !!");
new Helloworld().sayHello();
}
private native void sayHello();
}
The next step I took was to compile it outside the IDE (Intellij IDEA), using the command line option of javac -h ...
This produces a machine generated Helloworld.h file.
Next I wrote an equally elementary C program, code here :
#include "Helloworld.h"
JNIEXPORT void JNICALL Java_Helloworld_sayHello(JNIEnv *, jobject){
printf("\nSay something... Anything...");
}
This I tried compiling using VS 2022 dll option, first with pre-compiled headers, and then without the precompiled headers, but no luck. A vast array of errors manifested themselves. It would have been ideal to have this compiled within the VS environment, since the actual code that is planned to be called from Java contains a mix of C and AVX512 assembly, so having the IDE support would have been ideal (especially during debugging). Any advice on how to compile this to a .dll library that would be acceptable to Java would be very welcome.
Then I moved out of VS 2022, and used the following command line compilation string :
cl /c /I "C:\\Program Files\\Microsoft\\jdk\\include\\" /I "C:\\Program Files\\Microsoft\\jdk\\include\\win32\\" .\Helloworld.c
This gives the following very persistent error :
Microsoft (R) C/C++ Optimizing Compiler Version 19.31.31106.2 for x64
Copyright (C) Microsoft Corporation. All rights reserved.
Helloworld.c
.\Helloworld.c(3): error C2055: expected formal parameter list, not a type list
I tried changing the formal parameter from jobject to jobject j, but that did not succeed (obviously, since the definition in the jni.h states jobject is a typedef for a _jobject *).
I tried to undefine the __cplusplus by using the cl command option /U __cplusplus but no joy. Not sure what to try next.
Any advice is welcome.
Thanks
From Microsoft's documentation:
expected formal parameter list, not a type list
A function definition contains a parameter type list instead of a formal parameter list. ANSI C requires formal parameters to be named unless they are void or an ellipsis (...).
void func(int, char) {} // C2055
void func (int i, char c) {} // OK
Your function definition is the one in your .c file, i.e.
JNIEXPORT void JNICALL Java_Helloworld_sayHello(JNIEnv *, jobject) {
...
}
which you need to change into something like
JNIEXPORT void JNICALL Java_Helloworld_sayHello(JNIEnv *env, jobject thiz) {
...
}
Any corresponding function declaration (e.g. in a .h file) should work with or without parameter names.
I know this question has been asked here many times before. I've read all those questions that I can find along with information outside of stackoverflow. So far I haven't found an answer i can figure out that will solve the specific problem that I'm having.
here is the code for the unmanaged c++ dll header file.
namespace MyWin32DLL
{
class MyWin32ClassOne
{
public:
static __declspec(dllexport) int Getvar();
};
}
Here is the code for the c++ dll cpp file
#include "MyWin32ClassOne.h"
namespace MyWin32DLL
{
int MyWin32ClassOne::Getvar()
{
return 123;
}
}
This code i've put together from various sources so it may not be right at all. I'm not very experienced with c++ or dll's.
Here is the code from my silly little c# winforms prog that I attempt to access the dll with. (edited to correct type mismatch as pointed out by tolanj in the comments)
namespace TestDll
{
public partial class Form1 : Form
{
[DllImport("MyWin32CppDll.dll", CallingConvention = CallingConvention.StdCall)]
public static extern int Getvar();
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string response = Getvar().ToString();
MessageBox.Show(response, "title", MessageBoxButtons.OK);
}
}
}
Now, at this point i understand that i'm probalby getting the "no entry point" error because of how the c++ compiler mangles the names of methods and functions.
From what i've read there are two things I can do to solve the problem.
Thing 1
Add extern "c" before my declaration so the name doesn't get mangled by the compiler.
namespace MyWin32DLL
{
class MyWin32ClassOne
{
public:
extern "C" static __declspec(dllexport) int Getvar();
};
}
When i try this I get an error from Visual Studio stating that "linkage specification isn't allowed".
Ok, so I try thing 2 which is to use dumpbin to find the mangled name of my function and use the mangled name as the entry point in the dllimport call.
So i run dumpbin /symbols on my dll and i get no function name, mangled or otherwise.
Dump of file mywin32cppdll.dll
File Type: DLL
Summary
1000 .data
1000 .idata
2000 .rdata
1000 .reloc
1000 .rsrc
4000 .text
10000 .textbss
Next i try dumpbin /exports
Dump of file mywin32cppdll.dll
File Type: DLL
Section contains the following exports for MyWin32CppDll.dll
00000000 characteristics
554CF7D4 time date stamp Fri May 08 13:52:20 2015
0.00 version
1 ordinal base
1 number of functions
1 number of names
ordinal hint RVA name
1 0 00011005 ?Getvar#MyWin32ClassOne#MyWin32DLL##SAHXZ = #ILT+0(?Getvar#MyWin32ClassOne#MyWin32DLL##SAHXZ)
Summary
1000 .data
1000 .idata
2000 .rdata
1000 .reloc
1000 .rsrc
4000 .text
10000 .textbss
Looking at that I don't see a mangled or decorated name to use. But as a larth i use "Getvar#MyWin32ClassOne#MyWin32DLL##SAHXZ" as my entry point and still get the same error in my c# program.
Obviously I've missed something. How do I access the dll function from my c# program?
The name has been mangled, as you have observed. You've managed to omit the ? at the beginning of the mangled name. Your import should be:
[DllImport("MyWin32CppDll.dll", CallingConvention = CallingConvention.Cdecl,
EntryPoint = "?Getvar#MyWin32ClassOne#MyWin32DLL##SAHXZ")]
public static extern int Getvar();
Do note also that your function uses the cdecl calling convention.
I've run into a problem driving me mad. I've implemented a timer using the followin timer entry construct:
typedef std::multimap<boost::posix_time::ptime, events::ITimeout*> TEntryMap;
TEntryMap entries_;
and I insert elements into the multimap with:
boost::posix_time::ptime tTimeout = boost::posix_time::microsec_clock::local_time() + boost::posix_time::milliseconds(timeout);
entries_.insert(std::make_pair(tTimeout, ptr)); // ptr is the events::ITimeout object
and in one translation unit (cpp file) it works perfectly. However, now I need to move this functionality to another cpp file, and now I get a compilation error:
1>Build started 2013-02-07 15:38:18.
1>ClCompile:
1> EventDispatcher.cpp
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\utility(260): error C2678: binary '=' : no operator found which takes a left-hand operand of type 'const boost::posix_time::ptime' (or there is no acceptable conversion)
1> ....\boost\boost\date_time\posix_time\ptime.hpp(57): could be 'boost::posix_time::ptime &boost::posix_time::ptime::operator =(const boost::posix_time::ptime &)'
1> while trying to match the argument list '(const boost::posix_time::ptime, const boost::posix_time::ptime)'
1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\utility(259) : while compiling class template member function 'std::pair<_Ty1,_Ty2> &std::pair<_Ty1,_Ty2>::operator =(std::pair<_Ty1,_Ty2> &&)'
1> with
1> [
1> _Ty1=const boost::posix_time::ptime,
1> _Ty2=events::ITimeout *
1> ]
1> ....\eventdispatcher.cpp(72) : see reference to class template instantiation 'std::pair<_Ty1,_Ty2>' being compiled
1> with
1> [
1> _Ty1=const boost::posix_time::ptime,
1> _Ty2=events::ITimeout *
1> ]
1>
I'm clueless and been struggling with this for 2 hours. I see no difference between the working implementation, and the non-working one. The same construct, same multimap, same includes, same everything! ;(
I found the cause of the problem, and it smells like a VS2010 C++ compiler bug (when using std::remove_if). In a function implementation later on in the class using the construct, I tried to remove elements in the map with:
void removeEntry(events::ITimeout* p)
{
std::remove_if(entries_.begin(), entries_.end(),
[&](TEntryMap::value_type& entry)->bool
{
return (entry.second == p);
}
);
}
Changing that code to:
void removeEntry(events::ITimeout* p)
{
TEntryMap::iterator it = std::find_if(entries_.begin(), entries_.end(),
[&](TEntryMap::value_type& entry)->bool
{
return (entry.second == p);
}
);
if (it != entries_.end()) entries_.erase(it);
}
makes the insertion code work. Go figure. Note that even if I use a struct based predicate instead of a lambda closure, it still doesn't work with std::remove_if...
When I use the code
cvCreateButton("button1",callbackButton2,NULL,CV_PUSH_BUTTON,1);
void callbackButton2(int state, void *pointer){
int i = 2;
return;
}
I get the following error in visual studios 2010
error C2065: 'callbackButton2' : undeclared identifier
Could someone please explain what I am doing wrong to cause this error
Thanks
Based on the code presented it appears that callbackButton2 is used on the first line but is declared after this on the second line.
In most languages this is not a legal thing to do because an identifier is not valid until the compiler can determine the context(s) in which it can be used which is what declaring an identifier does
Try this:
void callbackButton2(int state, void *pointer){
int i = 2;
return;
}
cvCreateButton("button1",callbackButton2,NULL,CV_PUSH_BUTTON,1);
In that code sample the identifier callbackButton2is declared as a function before being used as an argument to the cvCreateButton function and should therefore be a valid use of the identifier