I'm making my first steps with D, and as a trial I am trying to access a SOAP API via the Internet. I have a working C++ app (Visual Studio 2019, Windows 10) which uses the wininet library. I am using Visual D within Visual Studio.
Unfortunately I am falling at the very first hurdle.
module Win32D;
import std.stdio;
import core.sys.windows.windows;
import core.sys.windows.wininet;
int main()
{
HINTERNET hNet = InternetOpenA("XYZ", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
return 0;
}
The compiler (DMD) fails to recognize the wininet types (eg HINTERNET) or functions (eg InternetOpenA). If I go to the definitions in wininet.d I can see all the prototypes.
The D tutorial suggests: "The import statement makes all public functions and types from the given module available."
I am guessing the answer is a one-liner, so I'd appreciate any help!
Related
I am totally unfamiliar with C-Sharp so this is all new to me but I have a framework I am trying to use with mono.
I can import functions from the framework fine, but there are a lot of for instance type definitions (in the form of C preprocessor directives not that I imagine that should make any difference) and definitions of all the error codes.
Now one thought is to just include the header files in the project, but am I right in thinking there is a way to just import them from the framework directly and how do you go about doing so?
As an aside I am working on Mac OS 10.9.1 using Xamarin Studio so any Visual Studio specific solutions will be ineffective.
I am trying to create unit from Delphi7 > Project > Import Type Library from mqoa.tlb or mqoa.dll, both on WinXP and on Win2003, and even more on Win7x64 (both mqoa30.tlb and mqoa.tlb (or *.dll), which stands for MSMQ 4.0) - every time it fails with error "Element not found".
According to MSMQ releases, on Windows 2003 and Windows XP "MSMQ 3.0" is installed, but in my old project I have MSMQ_TLB.pas generated from mqoa20.tlb ("C:\WINDOWS\system32\mqoa20.tlb"). I want to switch to MSMQ 3.0 Interfaces, but I cannot.
Any suggestions?
By the way, once upon a time I found on internet MSMQ Delphi Example, using MSMQ_TLB.pas generated, probably for MSMQ 3.0, here is snippet from *TLP.pas header:
// Type Lib: C:\WINDOWS\system32\MQOA.DLL (1)
// LIBID: {D7D6E071-DCCD-11D0-AA4B-0060970DEBAE}
// LCID: 0
// Helpfile:
// HelpString: Microsoft Message Queue 3.0 Object Library
// DepndLst:
// (1) v2.0 stdole, (C:\WINDOWS\system32\stdole2.tlb)
I do not know if I can use it reliable in my project, replacing old one *TLB.pas (file uploaded here, project here).
Please advice - I am in total confusion what and how to use.
I succeed doing it by installing newer version of Delphi (in my case - Delphi 2007):
Main menu > Component > Import Component > Import Type Library...
After this, generated file(s) MSMQ_TLB.PAS (and *.dcr) are usable for Delphi 7 too.
I am writing lib files in VS that have to be imported into CVI.
Recently a linker problem occured.
It says that _allmul() is an undefined symbol.
_allmul() and freinds are implemented as calls to the CRT library functions to handle various 64bit operations.
The lib file that i write is static because i want all the code to live inside it.
Linking with VS is no problem and all unittests pass.
Linking with the CVI-IDE leaves the CVI Linkter complaining about an unresolved _allmul().
I thougth that setting the /MT switch in VS is enough to make the CRT link statically, this seems to be wrong.
Why is my assumtion wrong?
How can i link the CRT calls statically?
Edit:
Here is a short demo of a project that i can compile in VS2010 but that i can not link to in CVI
The following is compiled as a LIB project:
HEADER
void print( unsigned A, unsigned B );
CODE
#include "MyprintInterface.h"
#include <stdio.h>
void print( unsigned A, unsigned B ){
long long copyA = ( long long ) A;
long long copyB = ( long long ) B;
printf_s( " %lli * %lli = %lli ", copyA, copyB, copyA * copyB );
// copyA * copyB -> this invokes allmul
// printf_s this is a ms specific function
}
This is a little late, but maybe it will help someone else.
I had very similar experience when using the gSoap toolkit with LabWindows/CVI. The toolkit generates ANSI C bindings used in creating web service clients or servers. However it sometimes generated versions of MS functions (some deprecated) that were prototyped slightly different than those in CVI. Solving this was kind of tedious, but generally followed these steps:
1) install appropriate Microsoft SDK onto your dev box. Here is one option for Microsoft SDKs. (There are others, Google it)
2) search MSDN website for the unresolved symbol to determine what .lib/.h support it. (MSDN list of variations of sprintf, for example)
3) include any required .lib/.h files.
4) make sure msvcr80.dll or msvcr100.dll (or other as appropriate) are visible to your executable. (i.e. place either in the executable run-time directory, or in the system directory.)
In addition to this I had to bring some of the #defines from the header files supporting file write/read functions, just
for example:
#define _O_TEXT 0x4000 /* file mode is text (translated) */
#define _O_BINARY 0x8000 /* file mode is binary (untranslated) */
And: (Requires Microsoft Platform SDK be installed
c:\program files\microsoft platform sdk\include\crt (copied to project dir and included in project))
fcntl.h (definition for file mode etc., _O_BINARY)
float.h (definition for isnan etc.)
io.h (definition for setmode etc.)
Also, there is an example CVI project with source code illustrating what I have described above, (including using crt) here.
[EDIT]
Regarding COFF compatible .libs when using third party libraries with respect to LabWindows/CVI - Read the posts here.
[EDIT 2]
Once you install the Windows SDK, the headers for everything in msvcrxxx.dll will be on your system. But for finding .h dependancies of a specific API call I typically have good luck just searching for it on Google: i.e. for sprintf_s et. al., the first link returned was this. It includes notes on how to use sprintf_s including source code.
As for allmul issues, I have not run into this before, but this guy did.
I’m tring to add OLE support to my program. I started by compiling one of the Qt examples:
http://doc.qt.digia.com/stable/activeqt-comapp.html
This example, export 1 class and 2 types:
QAXCLASS(Application)
QAXTYPE(Document)
QAXTYPE(DocumentList)
In order to test it, I import it in Microsft Visual C++ (add class, MFC class from Typelib)
The problem is that, after import, my classes are renamed:
CApplication
CDocument
CDocumentList
So when I call CApplication::Getdocuments() it returns a DocumentList* and this class is unknown!
What am I doing wrong?
EDIT: tested in a VB project, and it works fine! So there must be something wrong when importing the tlb in VC++
The computer lab in my High School , where I do my work for my CS course, has horribly outdated versions of java/jdk and the Netbeans IDE ( both 5.0 I believe) .
Netbeans startup takes an eternity, with frequent lockups, to the point that it interferes with my ability to hand in work on time. For this reason I used gvim to edit the .java files and compile and run them with Netbeans.
Since it's windows, I don't have the luxury of being able to just use javac to run the files. In fact the command prompt is completely locked down on the computers for whatever reason.
Is the a way to do the work of compiling and packaging without the use of a proper IDE or the command line?
Yes, you can do that, but it requires a bit more work. In Java 6, there's an API that allows you to call the compiler to compile source code. See this link for more information.
That solution assumes you have access to a Java 6 solution somehow, which I doubt very much given the version of NetBeans installed.
The other solution is of course to use something else as your environment for compiling or running the files. There's a Java editor that runs from a USB flash drive at this link
that might just be what you are looking for. It's smaller and faster than NetBeans and I find some of my students are using it more than any other editor. Make sure you follow the instructions for making it work from a flash drive. Also, if you don't pick the right language during installation, it defaults to German, achtung!
I know you don't want an IDE but Dr.Java is a super lite IDE for java. To be honest its barely an IDE at all more like a text editor with a compiler built in. No precompiling, no code completion, and the debugger doesn't do much more than stop at breakpoints. Its used mainly as a teaching tool for java but it certainly fits what you're describing!
You could write your own Java program that
Allows a developer to choose a file to compile and run.
Retrieves the system compiler and compiles the file.
Launches the compiled Java program.
Hey, I just wrote it for you. That was tons of fun to write. Please excuse the lack of modularity, I just hacked it out in 15 minutes. Of course you would have to compile and package the below Java program in a .jar file that you could then double click on to run it.
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.OutputStream;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.tools.JavaCompiler;
import javax.tools.ToolProvider;
public class Launcher {
public static void main(String[] args) {
try {
// Let the programmer choose the Java file to be compiled and executed.
JFileChooser chooser = new JFileChooser();
int response = chooser.showOpenDialog(null);
if (response == JFileChooser.APPROVE_OPTION) {
File javaFile = chooser.getSelectedFile();
// Compile the Java file.
InputStream in = new FileInputStream(javaFile);
OutputStream out = new ByteArrayOutputStream(16);
OutputStream err = new ByteArrayOutputStream(2000);
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
String[] compileArgs = { javaFile.getAbsolutePath() };
int r = compiler.run(in, out, err, compileArgs);
if (r != 0) {
JOptionPane.showMessageDialog(null, err.toString(), "CompileError", JOptionPane.ERROR_MESSAGE);
}
else {
// Since the file compiled successfully, run the compiled class.
String filename = javaFile.getName();
int dot = filename.lastIndexOf('.');
String className = filename.substring(0, dot);
String[] command = {
"javaw",
className,
};
ProcessBuilder pb = new ProcessBuilder(command);
pb.directory(javaFile.getParentFile());
pb.start();
}
}
}
catch (Exception ex) {
JOptionPane.showMessageDialog(null, ex.toString(), "Error", JOptionPane.ERROR_MESSAGE);
}
}
}