I created dll from c function and importing into c#
When I call the dll function I am getting error:
Unable to load DLL 'subFunction.dll': Not enough storage is available to process this command. (Exception from HRESULT: 0x80070008).
How to fix it.
I am inclined to say you look at it from the wrong side - this is not a C# issue, it is a simple as it is error in C++. I suggest you put up a native C++ command line test and check whether this happens there too, then you go on and fix your code.
Without debugging we are sort of guessing what you made wrong - and that will never work. BUt this seriously looks like C# is totally irrelevant for the question and it is a pure C level issue.
Related
I can't reference ImageSearch.dll in my project. I've been trying for days and can't get any further. it seems to me that i'm the only one with this problem and i don't know what to do next. Is it possible to reference a .dll manually, for example via lines of code? It's nerve wracking and need this or a similar feature.
I keep getting the following error:
Could not add a reference to imagesearch.dll. Make sure the file is accessible and is a valid assembly or COM component.
enter image description here
Hope someone can help me...
That message is telling you that the dll you're trying to reference is something that .NET doesn't know how to work with automatically. This means it has no idea what functions are in the dll or how they work. So, if a dll isn't a .NET assembly or exposed via COM, then you can use PInvoke (Platform Invoke).
Don't add the dll as a reference to your project at all, instead add it as a content file that gets output with the rest of your compiled code. Getting PInvoke to work with an arbitrary DLL can be quite complicated, so be prepared for some headaches. There's an entire website with examples of how to pinvoke for all sorts of libraries at http://pinvoke.net/ that will give you lots of ideas.
Then you can call methods in the dll by doing something like:
// Import ImageSearch.dll (containing the function we need) and define
// the method corresponding to the native function.
[DllImport("ImageSearch.dll"]
private static extern int FindImage(string imagePath);
Obviously I have no idea what imagesearch.dll is or does, so I have no idea what the actual PInvoke function should look like, you'll have to figure that out from the dll's interface.
https://learn.microsoft.com/en-us/dotnet/standard/native-interop/pinvoke
I've been on a quest for a while now to pass the PCM of an MP3 from W8.1/WP8.1 to Unity3D and I believe I'm getting close. I was referred to this project which works absolutely fine but, of course, it's in VB.NET so it can't be used with Unity. VB and C# are fairly similar so I set out to translate it. You can see my translation at this pastebin.
The problem occurs on line 97. The app simply exits with absolutely no indication of what went wrong. Calling any non-inherited function on the interfaces IMFSample and IMFMediaType has the same effect.
A friend suggested getting the HRESULTs from these functions to see if anything shows up. Google shows getting HRESULTs from COM interops in C# is.. hard. I experimented by changing IMFSample.GetSampleFlags to
int GetSampleFlags(out int pRetVal);
And that returned "The requested attribute was not found. (Exception from HRESULT: 0xC00D36E6)" and I'm not really sure what to do with that information...
So, I humbly ask you all... just... just what? What do I do from here?
--- SOLUTION ---
So as it turns out the solution was a little dumber than I expected.
I did not know this, but apparently COM interfaces that inherit from other COM interfaces have to include ALL of the methods from the parent COMs. Otherwise windows, it seems, throws a hissy fit.
That was it... it was my own laziness in the first place that killed me.
My Google-Fu has obediently told me that the following error
Not able to perform the operation because object is not given storage yet (Exception from HRESULT: 0x80040012 (OLE_E_NOSTORAGE))
which is being thrown from a C++ function called in a C# project is, in fact, an error which is related to OLE. But I can't find much more beyond that - what might cause such an error, or what functions would return it.
More baffling is the fact that although I know the code I'm using has spat out this error before, I personally haven't been able to reproduce it. It's coming from a pair of unit tests, so I doubt that I'm missing some vital step to reproduce the error, unless it's due to some arcane machine configuration. Can anyone help me understand where it might be coming from?
Using a console application, I'm making use of a c++ com dll to call a function.
I have added the registered DLL as a reference for the project and then I am instantiating the object and calling the function. (I should note that I'm not using pinvoke as some other people seem to be)
I should be getting a string back as a result but I am just getting an empty string. The only way I can get any form of output is by enabling debugging for unmanaged code and from that I can see that it is executing correctly and returning a result.
I have had a search around stackoverflow and a few other sites and can't quite find anything that matches this. Any ideas what I'm doing wrong or how I can get it to return a value?
EDIT: As requested, here is the code -
COMMODCHECKLib.Modcheck mod = new COMMODCHECKLib.Modcheck();
string output = mod.check("123456");
I would suggest to first check, if the problem is within the C# code or the COM library. For that, you can use e.g. a VB-Script file (.vbs) like
(test.vbs)
Set mod = CreateObject("COMMODCHECKLib.ModCheck")
WScript.echo(mod.check("123456"))
Just run this script from the command line (entering test.vbs).
If this gives the desired output, you know at least, that the problem lies on the C# side.
Well it seems that the documentation for the DLL was incorrect and gave the check function as the one I needed but infact there was a function called checkAllocate which is the one I needed to use. Apologies guys - many thanks for your time and efforts
I am attempting to convert a c# to c++ with reflector. The code compiled, disassembled and reconstructed code is generating this error:
1>c:\users\user\documents\visual
studio
2008\projects\reflect_readoo\reflect_readoo\readoo.cpp(2)
: error C2059: syntax error : 'public'
1>c:\users\user\documents\visual
studio
2008\projects\reflect_readoo\reflect_readoo\readoo.cpp(2)
: error C2143: syntax error : missing
';' before '{'
1>c:\users\user\documents\visual
studio
2008\projects\reflect_readoo\reflect_readoo\readoo.cpp(2)
: error C2447: '{' : missing function
header (old-style formal list?)
As I am unfamiliar with C++ syntax I'm not 100% sure where to start with these errors. The first the thing I tried was to remove all of the complicated code and just let the whole thing (it's one class in a namespace) be just a cout << "test"; in the namespace and class. removed the "ref" keyword, which removed the top error (this causes a million new errors wwith all of the functions in place) , but then was told a could only use a namespace if compiled with the clr flag, which would somewhat defeat the point of what i'm trying to do.
Can anyone recommend a path of testing that I could head down to start with? Otherwise, can anyone recommend a better way to translate a windows.form c# program into unmanaged c++? Should I just do it myself? (I want to do this eventually anyway, but it'd be a huge help to just have the damn thing and be able to look through and quickly see the differences, and I need the program for myself asap).
Thank you so much for any help, advice or guidance.
I understand the difficulty with the presentation side, I actually was not expecting for that to work, I just asked out of a dreamy hope. However, I would like to translate the "backend" of the application that was originally a console app. that I simply added as a class file to my windows form design. It's only this class of about a 1000 lines.
snippet:
public ref class RProgram {
public:
static System::String ^KeywordsLog = "Keywords.log"; // WHERE THE PROGRAM KEEPS ITS LOG
// classes. . . functions. . . the errors are reported on the first lines
};
for that then I understand, and concede the impossibility I suppose then, but could someone be so kind as to please help me resolve the errors preventing its compilation as managed c++?
You're going to have a very difficult time translating any reasonable complex Windows Forms application from C# to unmanaged C++.
You will not have access to any of the .NET framework libraries, which means no Windows Forms. You'll need to choose a different API for your windowing, such as MFC.
In general, this means that you'll need to completely rearchitect your applicaiton - at least the presentation side of it. My normal rule of thumb would be not to bother doing this - you have a working application, just keep it.