Why do I get run-time error 453 when I try to use a VB.NET dll that uses DllExport? - visual-studio-2019

I created a .NET dll by referencing DllExport provided by https://github.com/3F/DllExport/ in VS 2019. I used the DllExport.bat file to configure my test solution. I call a function/sub from the dll in Excel macro. It generates the error "Can't find DLL entry point".
I use VS 2019 to create the .NET dll. I have used DllExport attribute to export the function. Also I use Excel 2013.
I also tried to use UnmanagedExports NuGet package instead of DllExport Nuget package. It produces the same run-time error 453 "Can't find DLL entry point".

Related

Creating a F# PCL for Universal apps (a.k.a. Store Apps or Windows apps or WinRT apps)

Since Visual Studio 2013 Update 2, it is possible to create Portable Class Libraries (PCLs) that can reference Windows Runtime types (which was not possible before) as long as they only target Windows 8.1 and Windows Phone 8.1 and no other targets.
I tried this in C# by adding a C# Class Library (Portable for Universal Apps) and it works, which means that you can consume and produce Windows Runtime types as if the project was a Windows App or Windows Runtime Component.
Since F# also supports PCLs and Windows 8.1 and Windows Phone 8.1 are supported targets, I would like to achieve the same with F# PCLs (if possible). While Visual Studio 2013 Update 4 does not offer creating F# PCLs that only target Windows 8.1 and Windows Phone 8.1, it is possible to modify the .fsproj file of an F# PCL to match the .csproj file of a C# PCL with those targets that was created with Visual Studio. This requires changing the XML elements to the following:
<TargetFrameworkVersion>v4.6</TargetFrameworkVersion>
<TargetFrameworkProfile>Profile32</TargetFrameworkProfile>
and adding the following to an <ItemGroup>
<TargetPlatform Include="WindowsPhoneApp, Version=8.1" />
<TargetPlatform Include="Windows, Version=8.1" />
After these changes, I was able to consume and produce Windows Runtime types in the F# PCL as in the C# PCL (without complaints from Visual Studio in the F# PCL or C# (Universal) Windows App), but when I actually run the (Universal) Windows App I get the following exception when a function that uses Windows Runtime types is called in the F# PCL from the C# (Universal) Windows App:
An exception of type 'System.IO.FileNotFoundException' occurred in
[application name].exe but was not handled in user code
Additional information: Could not load file or assembly 'Windows, Version=255.255.255.255, Culture=neutral, PublicKeyToken=null' or one
of its dependencies. The system cannot find the file specified.
When I check the references in the Solution Explorer of Visual Studio, the C# PCL shows a reference named Windows, which is missing from the F# PCL. The Reference Properties of that reference look like this:
I tried adding this reference manually to the .fsproj file of the F# PCL by adding
<Reference Include="C:\Program Files (x86)\Microsoft SDKs\Portable\v12.0\110C4FEFF2BA61C0746933A9ED6E248D\Windows.winmd" />
to an <ItemGroup>. After this, the reference does show up in the F# PCL in the Solution Explorer with the following Reference Properties:
but does not fix the problem. That is, I still get the same exception as before.
I also tried copying and pasting the Windows reference via the context menu of the Solution Explorer of Visual Studio, but it complains with an error message.
Do you know how to properly add the Windows reference to a F# PCL? This would be really awesome, because that would make it possible to write (Universal) Windows Apps almost entirely in F#! If you know for a fact that this is not possible, then could you please explain what is preventing this from being possible?
EDIT: improved formatting of exception message
You're making a portable class library. F# does not support windows store apps, so the only way you can use F# in such a situation is to call it from C#. If you manage to succeed, you'll be the first of anyone.

Unable to reference FSharp.Core in LINQPad when referencing the FSharp.Data package

I am trying to use LINQPAD 4 to test HTML Parsing using F# and the FSharp.Data library. I proceeded as follows:
I created a new F# Program in LINQPad
Pressed F4 and added FSharp.Data as a NuGet package
I then tried to compile and run the following program in LINQPad
open FSharp.Data
let results = HtmlDocument.Load("http://www.google.co.uk/search?q=FSharp.Data")
results.Dump()
This returns a error telling me I need the assembly 'FSharp.Core, Version=4.3.0.0.
I then press F4 and add the required FSharp.Core assembly
I now get the following compiler error :
error FS1222: When mscorlib.dll or FSharp.Core.dll is explicitly
referenced the --noframework option must also be passed
This appears to be an issue with LINQPad which will be addressed in the next release (At the time of posting I was using LINQPad Premium 4.51.03 and .NET version 4.5.1 running on Windows 7 Professional 64 bit)
See this post on the LINQPad forum

Casablanca - REST C++ SDK, used in Embarcadero RAD Studio XE5

I need to do a http get in RAD Studio XE5 C++. The tutorials on the RAD Studio site discuss a RESTCLient that is not included with the version I have. I found the Casablanca project, which is specifically for Visual Studio, and I made a small program in VS that does the simple http get and handles response in the way I need.
What do I need to do to successfully use Casablanca from within RAD Studio?
There are the steps I have taken so far.
Compiled Casablanca in Visual Studio 2013
Copied the .lib and .dll over to a folder in the RAD Studio project
added that folder to the link path in the RAD Studio project
added the .lib to the project
added dll imports to classes that should be in the .lib to the .cpp I want to use the function in.
class __declspec(dllimport) http_client;
class __declspec(dllimport) filestream;
class __declspec(dllimport) producerconsumerstream;
class __declspec(dllimport) rawptrstream;
There was a OMF error, and I used a tool that came with RAD Studio to convert the .lib, that got past the error.
I don't know how to declare the dll prototype's of the functions, because the returns types are from a namespace in the library itself so they aren't recognized. http_client is an unrecognized structure.
I tried this as well without the class keyword.
DLLs that export classes are not portable across compilers. So you will not be able to use a Visual Studio compiled DLL in C++Builder if it exports classes. Either flatten the DLL interface to export plain C-style functions instead (and then use C++Builder's command-line IMPLIB tool to create an import .lib file for the DLL, do not use the .lib file created by Visual Studio), or else find another solution.
For instance, C++Builder (and Delphi) ships with Indy 10, which has a TIdHTTP component. You can use its TIdHTTP::Get() method to perform an HTTP GET request. But if you need to actually use REST, you might be better off simply upgrading your XE5 to a version that has TRESTClient available (BTW, Embarcadero's REST classes use Indy internally).

Namespace or module "Runtime" not defined

So the "Funscript" page here has a sample. Now I have loaded the sample into my Visual Studio 2012. I am not familiar with Visual Studio .NET and am only learning F# very recently. The last line in the sample pages which is:
do Runtime.Run(components=components, directory="Web")
always throws an error. In fact the Visual Studio IDE(Compiler) cannot seem to recognize Runtime.
If this was a language like Java, one would try to import a library and so I tried using System.Runtime, but still the Visual Studio IDE does not recognize and the line throws an error saying :
"The namespace or module "Runtime" is not defined.
Two questions
How can I get around this?
Is there any link that teaches
F# for the complete beginner that also involves loading external
libraries?
I figured this out. Funscript requires a launcher, which is talked about in the documentation. It is contained in Examples/Shared/Launcher.fs. If you use the .fsproj files that come with funscript, this is all handled automatically.
If you are compiling by hand, just add ../Shared/Launcher.fs before you compile your own file.

WSPBuilder cannot find my assembly

I am using WSPBuilder on Visual Studio 2010 to create a feature with a feature receiver assembly for SharePoint 2010. When I try to build the WSP using WSP Builder I get this message in the output window:
The assembly MyAssembly.dll is unmanaged. The assembly will be excluded from the WSP package!
The defined Project Assembly seems not to be a valid assembly!
Solution compatibility: SharePoint 2010
The resulting WSP that gets built does not contain my DLL.
My DLL is strongly named, and I cant think of any other obvious reasons why this is happening.
Any idea why WSPBuilder is not able to package my assembly in the WSP?
Ahh... Found the answer. My code was getting compiled against .Net Framework 4.0. Changed it to .Net Framework 3.5 and Voila! WSP gets built without any problems...

Resources