C# calling C++ error (instruction at referenced memory could not be read)


I have a C# assembly that is calling directly into C++ unmanaged code. Everything is working fine but at the very end of the process I get an application error, which says: "The instruction at (hexNumber) referenced memory at ...
Posted On: Monday 26th of November 2012 12:02:10 AM Total Views:  329
View Complete with Replies

RELATED TOPICS OF C Language PROGRAMMING LANGUAGE




calling a template class' template member function from a template function

I just ran into an issue where code that I was sure that is compilable and works turned out to not compile on GCC 4.2.1. Before dismissing it as a GCC bug I decided to have it tested on other systems and while MSVC 2005 and C++ Builder 6 work fine, Comeau on-line behaves just as GCC (GCC 4.1.0 and 3.4.4 and probably all the others give the same errors as 4.2.1). Since both GCC and Comeau give errors at the same point, chances are that my code is wrong. If that's the case, I wonder how to make it right. Also, I wonder if it is right that uncommenting the line with the global "void f(int, float)" makes the errors go away. So here's the code: >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> template struct X { template int f(); }; //template void f(int, float); // any parameter(s) would do template int g() { X tmp; return tmp.f(); // error }
VIEWS ON THIS POST

135

Posted on:

Sunday 4th November 2012
View Replies!

How to implement this function so that the vector can be passed backto the calling function?

I wrote a function which looks like: bool Xxx::findShortestPath(int xS, int yS, int xT, int yT, vector path) { .... } It meant to find a path, save the path in vector path, and pass the path back to the calling function. And in some other function (say, main()), I called this function like: int main() { .... vector path; xxx.findShortestPath(0, 0, 9, 9, path); // then print out the path } However, I just noticed that it failed to passed the path to the main() function. That is, in the function findShortestPath(...), the data has been loaded into *path*, but when it goes back to main(), all data is lost. I know this happens because of the memory management logic, but I am not clear about how to fix this and get what I want. Anybody gives some hints
VIEWS ON THIS POST

128

Posted on:

Sunday 4th November 2012
View Replies!

c++ calling c functions

hi, i am trying 2 merge 2 projects into one project.One project is using c language and the other one is using c++ code. both are working very fine independently.But now i need to merge both and my c++ code should call c code.but when i tried to call a function in c code externing that function in my c++ code, i am getting unresolved external symbol error. Whatever i try its giving more and more errrors...so is it possible to merge 2 projects if so how can i do that please reply.... - Thejaswini
VIEWS ON THIS POST

101

Posted on:

Sunday 4th November 2012
View Replies!

calling function

how can I call the put_ConnectionString correctly when I do the following I got compile error BSTR bstr = "aaa"; hr.put_ConnectionString(bstr); ################################### HRESULT CEPGLibApp::LoadXMLData(LPCTSTR tszXMLFileName) { HRESULT hr = S_OK; CComPtr pIXMLBulkLoad; hr = CoCreateInstance(CLSID_SQLXMLBulkLoad3, NULL, CLSCTX_INPROC_SERVER, IID_ISQLXMLBulkLoad, (void **)&pIXMLBulkLoad); if (SUCCEEDED(hr)) { BSTR bstr = "aaa"; hr.put_ConnectionString(bstr); } if (SUCCEEDED(hr)) { } if (SUCCEEDED(hr)) { } return hr; } ###################################### ISQLXMLBulkLoad : public IDispatch { public: virtual /* [helpstring][id][propget] */ HRESULT STDMETHODCALLTYPE get_ConnectionString( /* [retval][out] */ BSTR *pbstrConnectionString) = 0; virtual /* [helpstring][id][propput] */ HRESULT STDMETHODCALLTYPE put_ConnectionString( /* [in] */ BSTR bstrConnectionString) = 0; ################################ typedef /* [wire_marshal] */ OLECHAR *BSTR; ################################# typedef WCHAR OLECHAR; ################################
VIEWS ON THIS POST

125

Posted on:

Sunday 4th November 2012
View Replies!

cast behaviour? - calling rules?

In a test prototype I have started writing condition and value objects, so you can write a code as you can see later on (appendix). Notes: 1) The code is just for testing purpose! 2) Also 'next_index' is a const object it "does" increment. The 'const' is necessary to keep the temporary object! 3) Output (here as one line): 39, 37, 35, 33, ... ,1 The problem I have is with 'next_index'. I have to cast to invoke the logic. For condition objects this is done by the bool operator. Can I manage do invoke logic of an object without casting directly or calling a function operator appendix: int main() { int index = 0; int offset = 1; const int max = 40; const logic::condition& index_is_valid = compare_less_condition(index, max); const logic::condition& index_is_odd = compare_odd_condition(index); const value::interface& max_minus_index = value::difference(max, index); const value::interface& next_index = value::increment(index, offset); while (index_is_valid) { if (index_is_odd) std::cout
VIEWS ON THIS POST

117

Posted on:

Sunday 4th November 2012
View Replies!

Headers cross-calling

Hi all I have an-easy-to-resolve (I am sure but I am obviously unable to figure the answer out) problem for C++ gurus. Here's the situation I have fallen into... 2 header files: H1.h & H2.h -------------------------------------------------------------------- --- H1.h -------------------------------------------------------------------- #include "H2.h" //
VIEWS ON THIS POST

122

Posted on:

Monday 5th November 2012
View Replies!

constructor calling a member function?

This is a snippet from C++ FAQs, which I have never done--- when I do such a thing, I would declare function used by constructor ( in this example, init() ) as static. But I do understand that it would be great if the following practice is valid. But by OO concept, it seems not to very good because init() belongs to an object, which hasn't be constructed. Can you give any comment on my question class Foo { public: Foo(char x); Foo(char x, int y); ... private: void init(char x, int y); }; Foo::Foo(char x) { init(x, int(x) + 7); ... } Foo::Foo(char x, int y) { init(x, y); ... } void Foo::init(char x, int y) { ... }
VIEWS ON THIS POST

117

Posted on:

Monday 5th November 2012
View Replies!

calling other languages from C/C+

Hi NG. I have this predefined example of a tiny test dll, that does nothing but define the 2 functions STR2LOWER and STR2UPPER. I was told that the example was written in Borland C++Builder 4.5 some years back, but never the less, the code is still in use today it seems. I myself, code in C# and I haven't looked at any C/C++ in several years and I don't remember much of it. I have a few questions that somone using these languages on a daily basis probably can answer without breaking a sweat. 1) is it possible to make a dll like this one, use another dll i.e. a C#.NET one 2) if this is the case, how do one handle the return values of what would be C#-string -> C/C++ char* If anyone can give me an answer to any of this, it would be great with some examples, since I'm (as stated above) very rusty in these languages. This test dll is supposed to be called from within another application by the way, not from another language. Below is the dll example: --------------------------------------------------- START #include #include char *buffer = 0; const int STRMAX = 255; BOOL WINAPI DllEntryPoint(HINSTANCE hinstDll, DWORD fdwRreason, LPVOID plvReserved) { switch (fdwRreason) { case DLL_THREAD_ATTACH: case DLL_THREAD_DETACH: return 1; case DLL_PROCESS_ATTACH: // Put initialization code here (Run the first time DllOpen is called) // for each process buffer = (char*)malloc(STRMAX* sizeof(char)); if( NULL == buffer ) return 0; else return 1; case DLL_PROCESS_DETACH: free(buffer); return 1 ; } return 0; } #ifdef __cplusplus extern "C" { char* FAR PASCAL _export STR2LOWER (long, unsigned char*); char* FAR PASCAL _export STR2UPPER (long, unsigned char*); } #endif char* FAR PASCAL _export STR2UPPER(long dummy, char* argument) { return strcpy( buffer, AnsiUpper(argument)); } char* FAR PASCAL _export STR2LOWER(long dummy, char* argument) { return strcpy( buffer, AnsiLower(argument)); } --------------------------------------------------- END
VIEWS ON THIS POST

133

Posted on:

Monday 5th November 2012
View Replies!

API returns memory related error when calling inside a DLL

Hi , I am calling a third party API which takes one PVOID argument and returns data in it. It is a DLL application (Multithreaded dll). But every time this API returning a memory related error saying that error with buffer size. I am sure buffer size is enough. I tried with allocating memory dynamically as well but got the same result. Kindly suggest.
VIEWS ON THIS POST

127

Posted on:

Wednesday 7th November 2012
View Replies!

Destrying and object without calling a destructor

Hi , I have a large number of objects living in a double loop (see below, where CYCLES and NUMBER are huge). //////////////////////////////////////////////////////////////// for (t=0; t < CYCLES; t++) { for(i=0; i
VIEWS ON THIS POST

115

Posted on:

Wednesday 7th November 2012
View Replies!

calling class method

Let's say I have two classes A and B with B inheriting from A with one non virtual method : class A { public: void MethodA() { cout
VIEWS ON THIS POST

109

Posted on:

Wednesday 7th November 2012
View Replies!

c++ calling c functions

hi, i am trying 2 merge 2 projects into one project.One project is using c language and the other one is using c++ code. both are working very fine independently.But now i need to merge both and my c++ code should call c code.but when i tried to call a function in c code externing that function in my c++ code, i am getting unresolved external symbol error. Whatever i try its giving more and more errrors...so is it possible to merge 2 projects if so how can i do that please reply.... - Thejaswini
VIEWS ON THIS POST

108

Posted on:

Wednesday 7th November 2012
View Replies!

A constructor calling another constructor (default constructor)?

I am having an argument with a colleague who insists that an overloaded constructor can call the default constructor using the initializer list syntax ---- something like this: class SomeClass { public: SomeClass() { std::cout
VIEWS ON THIS POST

117

Posted on:

Wednesday 7th November 2012
View Replies!

Is this like calling a virtual function at construction time?

Your compilers are correct. In your code sample, a call to `base->CallNextWork()' in main() is effectively a wrapper around `base->Work()', which is a virtual function and was overridden by Derived. -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ] , On Thu, 31 May 2007, Sam wrote: > ! > > I frequently read that at construction time "*this" has the type of the > class being constructed at the moment. This is usually written in > conjunction with calling virtual functions from constructors. This is only an illustration of the effects, though, not reality. Besides, it's really only limited to construction time. After that, every reference, pointer etc. will properly have the most derived class as the dynamic type. So you can rely on the behaviour you've seen. Sebastian Redl -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ]
VIEWS ON THIS POST

115

Posted on:

Wednesday 7th November 2012
View Replies!

Base Class pointers to Derived Classes calling functions.

. I have a base class (SPRITE), and using this base class I have derived a large number of derived classes (PERSON, BULLET, MISSILE, etc.). Now, at a certain point in my program, I have a pair of pointers, where ...
VIEWS ON THIS POST

95

Posted on:

Saturday 10th November 2012
View Replies!

Re: ambiguous method calling

I have troubles using templates with multiple inheritance, what generated an error (in both Visual Studio 2005 and g++ 3.3.0) refering to an ambiguous call. Ambiguous the type is given in the calling function, but the compiler needs the ...
VIEWS ON THIS POST

111

Posted on:

Saturday 10th November 2012
View Replies!

Sending large amounts of data from a dll to it's calling program - how is it done?

"Dan" wrote: >I was thinking I might >be able to put each line of the file into an element of the array. I think that a reasonable way would be to provide a DLL function that would return one ...
VIEWS ON THIS POST

94

Posted on:

Saturday 10th November 2012
View Replies!

do you know why this is calling segfault in qt?

int nejmensi; for (int i=1;i
VIEWS ON THIS POST

115

Posted on:

Saturday 10th November 2012
View Replies!

Templates calling other templates?

I'm designing a protocol stack framework. In my protocol stack framework, I have an arbitrary set of protocol stack layers that pass data between the layers. My framework has a function like "send()" that sends a message from the top ...
VIEWS ON THIS POST

109

Posted on:

Sunday 11th November 2012
View Replies!

calling generic template function from template specialization

I have two functions that are nearly identical (one validates a row and one validates a table). Since a table is open-ended (i.e., can have infinite rows) but a row is finite, there is one addtional line of code in ...
VIEWS ON THIS POST

111

Posted on:

Sunday 25th November 2012
View Replies!