Infolog in Visual Studio - microsoft-dynamics

I am working on Dynamics AX 2012 r3, and I am debugging a batch job using Visual Studio 2013. In the Dynamics AX debugger, I can see the infolog messages in the infolog panel.
Is there a similar panel or way to view infolog messages when debugging in Visual Studio?

For what purposes? I could be wrong, but I'm thinking no without customization.
You can just add code in \Classes\Info\add to do whatever you want as a workaround. If you're attaching VS to AX, then System.Console::WriteLine("This might appear in the VS Output window"); may work. See code snip at end of this post.
This has some good options to explore: http://dev.goshoom.net/en/2012/05/console-output-ax/
You may be able to just open both debuggers, and when an infolog comes in, it might appear in the AX Debugger.
Add the below to your Info class and then put a call to it in the add() method and you'll be able to review the event viewer for infologs if you just need to see what's output. This was my workaround for debugging batch jobs or things in the CIL that were difficult to track.
static server void writeToSystemEventLog(str _message, Exception _exception = Exception::Info, int _eventId = 0)
{
#define.logSource('Dynamics Ax')
#define.logName('Dynamics Ax Log')
System.Diagnostics.EventLog eventLog;
System.Diagnostics.EventLogEntryType entryType;
switch (_exception)
{
case Exception::Error:
entryType = System.Diagnostics.EventLogEntryType::Error;
break;
case Exception::Warning:
entryType = System.Diagnostics.EventLogEntryType::Warning;
break;
default:
entryType = System.Diagnostics.EventLogEntryType::Information;
break;
}
if (!System.Diagnostics.EventLog::SourceExists(#logSource))
{
System.Diagnostics.EventLog::CreateEventSource(#logSource, #logName);
}
eventlog = new System.Diagnostics.EventLog();
eventLog.set_Source(#logSource);
eventlog.WriteEntry(_message, entryType, _eventId);
}
The call:
static void Job99(Args _args)
{
info::writeToSystemEventLog("Alex Test", Exception::Info, 1);
}
Then in the event viewer:

Related

QT -- QTLowEnergyService->discoverDetails() does not discover non standard characteristics

I am writing a QT application for BLE on windows 10. The windows application is a BLE central, while the peripheral is running on an iOS device (tablet or phone). I pretty much followed the low energy scanner example and I can find the iOS device with the UUID of interest. The problem is that when the service is discovered and after issuing the discoverDetails() to get a list of the characteristics, the QT state machine goes from DiscoveryRequired, DiscoveringServices, Invalid Service, and then it disconnects.
I know this is a QT problem because
I can connect and interact with the peripheral using other applications
https://apps.apple.com/us/app/lightblue/id557428110
https://www.microsoft.com/en-us/p/ble-scanner/9nblggh0j7m0#activetab=pivot:overviewtab
The BLE scanner app (written in C#) from Microsoft, when compiled and run on the same machine as QT, also is able to connect and interact with the iOS peripheral.
I have noticed that other people are had/have the same problem, but I don't see where/if a resolution/workaround was eventually found.
Qt - Cannot read descriptor of the characteristic - BLE
Here is my handler for the QLowEnergyService::ServiceState signal
void BleClient::serviceStateChanged(QLowEnergyService::ServiceState newState)
{
switch (newState)
{
case QLowEnergyService::DiscoveringServices) :
{
// Nothing to do here, just note that we got into this state
qDebug() << "Discovering services";
break;
}
case QLowEnergyService::ServiceDiscovered:
{
qDebug() << "Service discovered";
const QList<QLowEnergyCharacteristic> chars = m_currentService->characteristics();
for (const QLowEnergyCharacteristic& ch : chars) {
auto cInfo = new CharacteristicInfo(ch);
m_characteristics.append(cInfo);
}
if (!chars.isValid()) {
setMessage("Value for characteristic not found.");
break;
}
m_notificationDesc = chars.descriptor(QBluetoothUuid::ClientCharacteristicConfiguration);
if (m_notificationDesc.isValid()) {
m_service->writeDescriptor(m_notificationDesc, QByteArray::fromHex("0100"));
setMessage("Characteristic enabled");
m_start = QDateTime::currentDateTime();
}
break;
}
default:
qDebug() << "Unhandled state received : (" << newState << ")";
}
}
Ok, figured it out. Added more debug code and saw that a very descriptive error was being logged:
QLowEnergyService error: UnknownError
Looking further, seems like , the QLowEnergyController needs a queued connection callback for the serviceDiscovered event to work as expected. So I changed
connect(controller, &QLowEnergyController::discoveryFinished, this, &BleClient::serviceScanDone);
to
connect(controller, &QLowEnergyController::discoveryFinished, this, &BleClient::serviceScanDone, Qt::QueuedConnection);
..and lo and behold, now I see all services with all the characteristics.

Why this code doesn't work when "cout"s are commented?

I'm writing a server for an online game based on IOCP, and the core codes handling game message is something like below:
CMessage ret;
int now_roomnum = recv_msg->para1;
int now_playernum = recv_msg->para2;
/*if(true)
{
cout<<"Received Game Message: "<<endl;
cout<<"type2 = "<<recv_msg->type2;
cout<<" player_num = "<<now_playernum<<" msg= "<<recv_msg->msg<<endl;
cout<<endl;
}*/
if(recv_msg->type2 == MSG_GAME_OPERATION)
{
ret.type1 = MSG_GAME;
ret.type2 = MSG_GAME_OPERATION;
while(game_host[now_roomnum].Ready(now_playernum) == true)
{
;
}
//cout<<"Entered from "<<now_playernum<<endl;
game_host[now_roomnum].SetMessage(now_playernum, recv_msg->msg);
game_host[now_roomnum].SetReady(now_playernum, true);
game_host[now_roomnum].SetUsed(now_playernum, false);
while(true)
{
bool tmp = game_host[now_roomnum].AllReady();
if(tmp == true)
break;
}
//cout<<"AllReady from"<<now_playernum<<endl;
string all_msg = game_host[now_roomnum].GetAllMessage();
game_host[now_roomnum].SetUsed(now_playernum, true);
while(!game_host[now_roomnum].AllUsed())
{
;
}
//cout<<"AllUsed from "<<now_playernum<<endl;
EnterCriticalSection(&cs);
game_host[now_roomnum].ClearReady();
LeaveCriticalSection(&cs);
strcpy_s(ret.msg, all_msg.c_str());
//cout<<"Return msg "<<now_playernum<<": "<<ret.msg<<endl;
}
return ret;
Now, the problem is: on a PC, when all cout are commented like above, the game freezes at once; but when I cancel the comments, the server works well.
What's more, when I run the server on my laptop, everything goes fine, no matter whether I comment the cout or not. The main difference between my laptop and PC is that my laptop's OS is Windows 8.1, while the PC is Windows 7.
I'm totally confused. It will be of great help if someone can tell me what to do. Thank you!
Looks like a multithreading issue.
By the way I see you use a Critical section around ClearReady but not when testing for AllReady. That call should be wrapped as well (or, better, write a LockedAllReady that makes use of the lock).
//cout<<"Return msg "<<now_playernum<<": "<<ret.msg<<endl;
What you mean by ret.msg? if msg is method you must do ret.msg(); , is it a field?
If you have this good then like they say above probably a timing problem, try to do cout without ret.msg and see what will happen, and then you know from where the problem is.

Visual C++ System::Windows::Forms::SaveFileDialog() throws System.AccessViolationException and quietly kills application if started by drag/drop

In a simple application (a skeleton put together with Visual Studio designer) I recently worked around an error that only manifests if I use drag/drop to execute the program.
Problem: I drag and drop a file onto my program. I later use File->SaveAs to save the contents of a rich text box. If I attempt to type a filename or drop down the hierarchy of directory paths, the application instantly quits. If I select a file displayed in the SaveAs dialog, this works fine (after accepting the overwrite).
Workaround: Add a try/catch block above the ShowDialog call in the saveAsToolStripMenuItem_Click function containing an attempt to open and write to a file. A simple fputs will cause the exception, which I then ignore and delete any file created in the process.
If someone knows a simpler (or cleaner!) solution, thanks in advance. Otherwise, here is my ugly solution:
private: System::Void saveAsToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e)
{
static bool fFirstTime = true;
static char *sBogusFileName = "c:\\__$$TrashFileIMustCreateThenDelete";
SaveFileDialog^ dialog = gcnew SaveFileDialog();
{
System::Windows::Forms::DialogResult DR;
dialog->Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
dialog->FilterIndex = 2;
dialog->RestoreDirectory = true;
// dialog->InitialDirectory = "c:\\";
if (fFirstTime)
{
FILE *fp;
// This is a strange problem that came up on my Windows XP machine.
// The first time through this logic, I would get a System.AccessViolationException
// If I do it with this simple fputs, the error is recoverable.
// If it happens during the dialog->ShowDialog that follows, the application quietly exits.
// No event logs, nothing. This solved it for me.
try {
// The fopen that follows make the MS compiler unhappy. The filename is hard-coded, so I don't care.
#pragma warning( suppress: 4996 )
fp=fopen(sBogusFileName, "w");
fputs("A string that might never be actually written - this causes an exception on some machines\n", fp);
}
catch(Exception ^e)
{
(void)e; // Suppress another compiler error (unused variable)
// Debug code that I later removed. This logging is not required to fix the problem.
// RRCLOGB1("\nError attempting to write to a file:\n%s\n\n", e->ToString());
}
finally
{
fclose(fp);
}
remove(sBogusFileName);
fFirstTime = false; // Only cause the exception once...but why is it necessary?!?
}
DR = dialog->ShowDialog(this);
if ( DR == System::Windows::Forms::DialogResult::OK )
{
o
o
o

Abnormal Execution after wglCreateContext in MFC based Application

We have a 32-bit Visual C++/MFC based (Multi-Document Interface-MDI) application which is compiled using Visual Studio 2005.
We are running the application on Windows Server 2008 R2 (64-bit) having ATI Graphics card (ATIES1000 version 8.240.50.5000 to be exact).
We are using OpenGL in certain parts of our software.
The problem is that the software is randomly crashing after executing the code related to initialization of an OpenGL based window. After including heavy tracing in the code, we found out that the program execution becomes abnormal after executing wglCreateContext() function; it skips the rest of the code for the current function for initializing of OpenGL based Window and instead starts executing the default View (drawing) function of the application (eg. ApplicationView::OnDraw).
After executing a few lines of code for the default view, the program generates an exception when trying to access a main document member variable. Our unhandled exception filter is able to catch the exception and generate an execution dump, but the execution dump does not provide much useful information either, other than specifying that the exception code is c0000090.
The problem is quite random and is only reported to appear on this Windows server environment only.
Any help or hints in solving this situation?
EDIT :
in other words, the program structure looks like this, with the execution randomly skipping the lines after wglCreateContext() function, executing a few lines of ApplicationView::onDraw and then causing an exception:
void 3DView::InitializeOpenGL()
{
....
Init3DWindow( m_b3DEnabled, m_pDC->GetSafeHdc());
m_Font->init();
....
}
bool 3DView::Init3DWindow( bool b3DEnabled, HDC pHDC)
{
...
static PIXELFORMATDESCRIPTOR pd = {
sizeof (PIXELFORMATDESCRIPTOR), // Specifies the size
1, // Specifies the version of this data structure
...
};
int iPixelFormat = ChoosePixelFormat(pHDC, &pd);
if(iPixelFormat == 0)
{
...
}
bSuccess = SetPixelFormat(pHDC, iPixelFormat, &pd);
m_hRC = wglCreateContext(pHDC);
//Execution becomes abnormal afterwards and control exits from 3DView::Init3DWindow
if(m_hRC==NULL)
{
...
}
bSuccess = wglMakeCurrent(pHDC, m_hRC);
....
return true;
}
void ApplicationView::OnDraw(CDC* pDC)
{
...
CApplicationDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
...
double currentValue = pDoc->m_CurrentValue;
//EXCEPTION raised at the above line
double nextValue = pDoc->nextValue;
}

Scriptable plugin: Error calling method on NPObject

I am getting a JavaScript error: Error calling method on NPObject when calling a method in my NPAPI plugin in Chrome & Firefox on XP. Running the same code on Windows 7 with the same browsers was successful.
I have built a Scriptable plugin using the NPAPI, so far I can debug into the Invoke method of my scriptable object. But I don't believe I have any control after it's finished.
Does anyone have any ideas? Is this an issue only in Windows XP?
bool MY_ScriptableObject::Invoke(NPObject* npobj,
NPIdentifier name,
const NPVariant* args,
uint32_t argCount,
NPVariant* result)
{
bool rc = true;
char* wptr = NULL;
rc = false;
wptr = NULL;
if (name == NPN_GetStringIdentifier("getVersion"))
{
wptr = (NPUTF8*)NPN_MemAlloc(strlen("version:1.0.1") + 1); //Should be freed by browser
if (wptr != NULL)
{
rc = true;
memset(wptr,
0x00,
strlen("version:1.0.1")+1);
memcpy(wptr,
"version:1.0.1",
strlen("version:1.0.1"));
STRINGZ_TO_NPVARIANT(wptr,
*result);
}
}
return (rc);
}
Here is the HTML function that I am executing:
function Version()
{
var plugin = document.getElementById("plugin");
if (plugin == undefined)
{
alert("plugin failed");
return;
}
var text = plugin.getVersion(); //Error happens at this line
alert(text);
}
The (sarcasm)awesome(/sarcasm) thing about NPAPI in current versions of the browsers is that if anything goes wrong with the call you automatically get that error message, even if the plugin has otherwise tried to set an exception with NPN_SetException.
My first guess would be that you compiled your code targeting a later version of windows than windows XP; I'm not sure if that would produce this issue or not. I have never seen the issue you're describing, and I've got plugins running on xp, vista, and 7 with no trouble. You might also try playing with a FireBreath plugin and see if the issue occurs there or not.
I would recommend that you attach with a debugger and set some breakpoints. Start in NPN_GetValue and make sure that it's instantiating your NPObject, then set breakpoints in your NPObject's HasMethod and Invoke methods and see what is hit. Likely something in there will show you what is actually happening, or at least tell you what code is or isn't getting hit.