Exception class $C0000005 with message 'c0000005 ACCESS_VIOLATION' - c++builder

I have created a WSDL service using RAD Studio (C++ Builder) and it works fine tested it using Microsoft Visual Studio . now i am trying to use this in as application in RAD studio (C++).
static const char* defWSDL= "http://localhost:8080/wsdl/IAndroidService";
static const char* defURL = "http://localhost:8080/soap/IAndroidService";
static const char* defSvc = "IAndroidServiceservice";
static const char* defPrt = "IAndroidServicePort";
if (addr=="")
addr = useWSDL ? defWSDL : defURL;
Soaphttpclient::THTTPRIO* rio = HTTPRIO ? HTTPRIO : new Soaphttpclient::THTTPRIO(0);
if (useWSDL) {
rio->WSDLLocation = addr;
rio->Service = defSvc;
rio->Port = defPrt;
} else {
rio->URL = addr;
}
No matter what i do i get an exception at either
rio->WSDLLocation = addr;
or
rio->URL = addr;
and here is the exception
Exception class $C0000005 with message 'c0000005 ACCESS_VIOLATION'
I am calling the service like this
Soaphttpclient::THTTPRIO* riod;
bool useWSDL = True;
_di_IAndroidService service = NS_IAndroidService::GetIAndroidService(useWSDL,"",riod);
Can someone please advise.
Thanks

Related

TIdTCPServer not working after upgrading to C++Builder 11

The following code worked in C++Builder 10.3 Rio to stream a file across the network. After upgrading to C++Builder 11 Alexandria, fileStreamerExecute() never gets called. The file does get created at path, but is zero length and is in use, so any attempt to open the file fails. I'm guessing some changes occurred with Indy and so some changes are required in my code?
//---------------------------------------------------------------------------
void Tdata::stream_file(String path, Tstream_dir direction)
{
_stream_path = path;
_stream_dir = direction;
if (_fs)
delete _fs;
if (_stream_dir == sdIn)
_fs = new TFileStream(_stream_path, fmCreate | fmShareDenyNone);
else
_fs = new TFileStream(_stream_path, fmOpenRead | fmShareDenyNone);
fileStreamer->DefaultPort = 9965;
fileStreamer->Active = true;
}
//---------------------------------------------------------------------------
void __fastcall Tdata::fileStreamerExecute(TIdContext *AContext)
{
if (_stream_dir == sdIn)
{
try
{
_fs->Position = 0;
AContext->Connection->IOHandler->ReadStream(_fs, -1, true);
}
__finally
{
delete _fs;
_fs = 0;
}
AContext->Connection->Disconnect();
}
else
{
try
{
AContext->Connection->IOHandler->Write(_fs);
}
__finally
{
delete _fs;
_fs = 0;
}
AContext->Connection->Disconnect();
}
}
// ---------------------------------------------------------------------------
__fastcall TstartForm::TstartForm(TComponent* Owner) : TForm(Owner)
{
char hostname[256];
String host_ip = "";
_progressForm = 0;
if (gethostname(hostname, 256) == 0) {
hostent *host = gethostbyname(hostname);
if (host) {
char *addr = host->h_addr;
if (addr) {
host_ip = String(inet_ntoa(*(in_addr*) addr));
// returns "192.168.180.1" from VMWare network adaptor
// hard code to correct value for testing
host_ip = "192.168.1.226";
}
}
}
}
EDIT: updated to get the local IP like this instead, and now things are working:
__fastcall TstartForm::TstartForm(TComponent* Owner) : TForm(Owner)
{
_progressForm = 0;
String host_ip = L"";
TIdStackWindows* id_stack = new TIdStackWindows;
if (id_stack) {
host_ip = id_stack->LocalAddress;
delete id_stack;
}
}
EDIT: updated to get the local IP per Remy's Recommendation
__fastcall TstartForm::TstartForm(TComponent* Owner) : TForm(Owner)
{
_progressForm = 0;
String host_ip = L"";
TIdStack::IncUsage();
host_ip = GStack->LocalAddress;
TIdStack::DecUsage();
sm->_this_computer_id = host_ip;
}

How to "talk" with USB device via my module?

I've written my module for gamepad that plugged by USB. I've already checked that my installed module detects my device successfully and even calls "probe" method:
static struct usb_driver driver =
{
.name = "Driver#1",
.id_table = table,
.probe = probe,
.disconnect = disconnect,
};
I have also written special urb function, that should "talk" with my device
usb_fill_int_urb(j->irq_in, udev,
usb_rcvintpipe(udev, ep_irq_in->bEndpointAddress), //!
j->idata, 32, irq_hh,
j, ep_irq_in->bInterval);
But I cannot understand how to initialize action of irq_in. I presume that I need to press something and some information should be written in j->idata. I also did
usb_submit_urb(j->irq_in, GFP_KERNEL);
But nothing happens! Why?
My probe function:
static void irq_hh(struct urb *urb)
{
struct devicec *j = urb->context;/*В какую структура из всех процессов дб заполнена после приёма данных???*/
char *data = j->idata;
printk(KERN_INFO "irq_hh: %s", data);
}
static int probe(struct usb_interface *intf, const struct usb_device_id *id)
{
struct usb_device *udev; //!
struct usb_endpoint_descriptor *ep_irq_in;
int ep_irq_in_idx, error;
printk(KERN_INFO "probe...%X",id->idVendor);
j = kzalloc(sizeof(struct devicec), GFP_KERNEL);
udev = interface_to_usbdev(intf);
j->irq_in = usb_alloc_urb(0, GFP_KERNEL);
//--------------------------------------
j->udev = udev;
j->intf = intf;
//--------------------------------------
usb_make_path(udev, j->phys, sizeof(j->phys));
strlcat(j->phys, "/input101", sizeof(j->phys));
printk(KERN_INFO "%s",j->phys);
ep_irq_in_idx = 0;
ep_irq_in = &intf->cur_altsetting->endpoint[ep_irq_in_idx].desc;
usb_fill_int_urb(j->irq_in, udev,
usb_rcvintpipe(udev, ep_irq_in->bEndpointAddress), //!
j->idata, 32, irq_hh,
j, ep_irq_in->bInterval);
j->irq_in->transfer_dma = j->idata_dma;
j->irq_in->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
error = usb_submit_urb(j->irq_in, GFP_KERNEL);
printk(KERN_INFO "%d",error);
return 0;
}

Why is there an exception using DialogResult::OK in C++ CLI

I am trying to open a picture and show it in picturebox but getting an exception.
I use visual studio 2017 c++ CLI.
I include those libraries in the beginning
#include<opencv2/core/core.hpp>
#include<opencv2/highgui/highgui.hpp>
#include<opencv2/imgproc/imgproc.hpp>
#pragma managed
#include <Windows.h>
#include <conio.h>
cv::Mat img; cv::Mat imgThresh;
Exception thrown at 0x00007FF9582E5D43 (comctl32.dll) in LPRCNN.exe:
0xC0000005: Access violation reading location 0xFFFFFFFFB2BEB41A.
occurred
private: System::Void btnBrowse_Click(System::Object^ sender, System::EventArgs^ e) {
//Stream;
Stream^ myStream;
OpenFileDialog^ openFileDialog1 = gcnew OpenFileDialog;
openFileDialog1->InitialDirectory = Directory::GetCurrentDirectory();
openFileDialog1->Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
openFileDialog1->FilterIndex = 2;
openFileDialog1->RestoreDirectory = true;
if (openFileDialog1->ShowDialog() == System::Windows::Forms::DialogResult::OK)
{
if ((myStream = openFileDialog1->OpenFile()) != nullptr)
{
file_path_temp = (openFileDialog1->FileName);
txtImgUrl->Text = file_path_temp;
IntPtr pointer_temp = Marshal::StringToHGlobalAnsi(file_path_temp);
const char* input_location = static_cast<const char*>(pointer_temp.ToPointer());
cv::Mat imgOriginalScene = cv::imread(input_location, CV_LOAD_IMAGE_ANYDEPTH | CV_LOAD_IMAGE_ANYCOLOR);
if (!imgOriginalScene.empty())
{
cvtColor(imgOriginalScene, img, CV_RGB2RGBA);
cv::imwrite("temp/temp.bmp", imgOriginalScene);
System::Drawing::Graphics^ graphics = PicBoxCar->CreateGraphics();
System::Drawing::Bitmap^ b = gcnew System::Drawing::Bitmap("temp/temp.bmp");
System::Drawing::RectangleF rect(0, 0, (float)PicBoxCar->Width, (float)PicBoxCar->Height);
graphics->DrawImage(b, rect);
delete b;
}
else
MessageBox::Show("Cannot open this image please choose another one !!", "Path:");
myStream->Close();
}
}
}

Directx Window keeps Crashing

My problem with this code is that when I run it in visual C++ A window pops up
but then it just crashes. It is not responding and I cannot click exit. I have to pull up the
task manager to get rid of the window. I am new to windows programming and direct X.
Below I will post were I think the problem is.
#include <d3d9.h>
#include <time.h>
#define APPTITLE "Direct3D_Windowed"
LRESULT WINAPI WinProc(HWND, UINT, WPARAM, LPARAM);
ATOM MyRegisterClass(HINSTANCE);
int Game_Init(HWND);
void GAME_RUN(HWND);
void GAME_END(HWND);
LPDIRECT3D9 d3d = NULL;
LPDIRECT3DDEVICE9 d3ddev = NULL;
// Over here, after GAME_END() is called, I tried separating the POSTQUITMESSAGE But I
I just got an error.
LRESULT WINAPI WinProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg )
{
case WM_DESTROY:
GAME_END(hWnd);
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hWnd, msg, wParam, lParam);
}
ATOM MyRegisterClass(HINSTANCE hInstance)
{
WNDCLASSEX wc;
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = (WNDPROC)WinProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = NULL;
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
wc.lpszMenuName = NULL;
wc.lpszClassName = APPTITLE;
wc.hIconSm = NULL;
return RegisterClassEx(&wc);
}
// I got this code from a book that I am reading and realized that WinProc is not being
called in this function. Is this the potential problem? Were would I put the WinProc
function call if it is supposed to be here in WinMain
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
MSG msg = {0};
MyRegisterClass(hInstance);
HWND hWnd;
hWnd = CreateWindow(
APPTITLE,
APPTITLE,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
500,
400,
NULL,
NULL,
hInstance,
NULL);
if(!hWnd)
return FALSE;
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
if(!Game_Init(hWnd))
return 0;
int done = 0;
while(!done)
{
if(msg.message == WM_QUIT)
{
if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
MessageBox(hWnd, "Recieve WM_QUIT message", "WinMain", MB_OK);
done = 1;
}
TranslateMessage(&msg);
DispatchMessage(&msg);
}
else
GAME_RUN(hWnd);
}
return msg.wParam;
}
int Game_Init(HWND hWnd)
{
MessageBox(hWnd, "Program is about to start", "Game_Init", MB_OK);
d3d = Direct3DCreate9(D3D_SDK_VERSION);
if(d3d == NULL)
{
MessageBox(hWnd, "Error initializing Direct3D", "Error", MB_OK);
return 0;
}
D3DPRESENT_PARAMETERS d3dpp;
ZeroMemory(&d3dpp, sizeof(d3dpp));
d3dpp.Windowed = TRUE;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.BackBufferFormat = D3DFMT_UNKNOWN;
d3d->CreateDevice(
D3DADAPTER_DEFAULT,
D3DDEVTYPE_HAL,
hWnd,
D3DCREATE_SOFTWARE_VERTEXPROCESSING,
&d3dpp,
&d3ddev);
if(d3ddev == NULL)
{
MessageBox(hWnd, "Error creating Direct device", "Error", MB_OK);
return 0;
}
srand(time(NULL));
return 1;
}
void GAME_RUN(HWND hWnd)
{
if(d3ddev == NULL)
return;
d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 255, 255), 1.0f, 0);
if(d3ddev->BeginScene())
{
d3ddev->EndScene();
}
d3ddev->Present(NULL, NULL, NULL, NULL);
}
void GAME_END(HWND hWnd)
{
MessageBox(hWnd, "Program is about to end", "Game End", MB_OK);
if(d3ddev != NULL)
d3ddev->Release();
if(d3d != NULL)
d3d->Release();
}
Have a look at this?
if(msg.message == WM_QUIT)
In your while-loop.
Perhaps change that to, say:
if(true)
Reason: you want your application to pass on all messages, not just the ones that cause it to quit. Say for instance when windows wants your application to draw itself. Basically, your current code doenst allow your application to do anything except quitting.
If you want to do something special when the application quits, add another case WM_QUIT: after the already existing case WM_DESTROY: in WinProc().
The current location for GAME_RUN(hWnd); will not work out for you.
You want to either put that in a seperate thread (easiest, and highest performance). Or you want to use some timers, and handle it with case WM_TIMER: after your case WM_DESTROY:. Or alternatively make up your own user defined message.

calling IDirect3D9::CreateDevice() from DllMain hangs

What can be a reason?
From DllMain() on DLL_PROCESS_ATTACH I'm calling IDirect3D9::CreateDevice() and it hangs
code is straightforward, just like:
BOOL APIENTRY DllMain( HMODULE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
if (ul_reason_for_call = DLL_PROCESS_ATTACH) {
IDirect3D9* d3d = Direct3DCreate9(D3D_SDK_VERSION);
D3DPRESENT_PARAMETERS pp = {};
pp.BackBufferWidth = 1;
pp.BackBufferHeight = 1;
pp.BackBufferFormat = D3DFMT_X8R8G8B8;
pp.BackBufferCount = 1;
pp.SwapEffect = D3DSWAPEFFECT_DISCARD;
pp.Windowed = TRUE;
IDirect3DDevice9* device = NULL;
HRESULT hr = d3d->CreateDevice(
D3DADAPTER_DEFAULT,
D3DDEVTYPE_HAL,
GetDesktopWindow(),
D3DCREATE_HARDWARE_VERTEXPROCESSING,
&pp,
&device);
device->Release();
d3d->Release();
}
return TRUE;
}
GetDesktopWindow() is used for simplicity, I tried to create own window and use it, the same result
You cannot do these kind of things in DllMain. Specifically, you cannot call functions from other DLLs. You can only do this from an exported function, when it is called by the main application.
Quoting the docs on MSDN:
Threads in DllMain hold the loader lock so no additional DLLs can be dynamically loaded or initialized.
Calling functions that require DLLs other than Kernel32.dll may result in problems that are difficult to diagnose. For example, calling User, Shell, and COM functions can cause access violation errors, because some functions load other system components.

Resources