Using EDITSTREAM CALLBACK

Hallo everyone! I've been having trouble using the EDIT STREAM CALLBACK.When I try to run my application, it fails with unhand-led exception access violation.Here my code.Any help will be highly appreciated.
case ID_BUTTONA:
            DWORD_PTR dwCookie;
    dwCookie = 0;
    DWORD   dwError;
    dwError = 0;
    EDITSTREAMCALLBACK EditStreamCallback;
    EditStreamCallback = NULL ;
    EDITSTREAM es;  
    hFile = (HANDLE)dwCookie;   
es.dwCookie    = (DWORD_PTR)hFile;
es.dwError =    dwError;
es.pfnCallback = EditStreamCallback;
    LPBYTE pbBuff;
    pbBuff = NULL;
    LONG cb;
    PLONG pcb;
    pcb = 0;
    DWORD   write;
     WriteFile(hFile, &pbBuff, write, (DWORD *)&pcb, NULL);//
dwpfn=GetLastError();
      swprintf_s(dwj,100,L"%d",dwpfn);
                        MessageBox(hWnd, dwj
                                   L"Problem with write file",
MB_OK);
EditStreamCallback( (DWORD_PTR)hFile ,pbBuff,cb,pcb);
SendMessage(richedit, EM_STREAMOUT, SF_RTF, (LPARAM)&es);
    hFile = CreateFile(L"Again.rtf",GENERIC_WRITE,
                              FILE_SHARE_WRITE, 0, CREATE_NEW,
                              FILE_ATTRIBUTE_NORMAL, NULL);
    if (hFile=INVALID_HANDLE_VALUE)
    dw2=GetLastError();
      swprintf_s(dw3,100,L"%d",dw2);
                        MessageBox(hWnd, dw3
                                   L"INVALID_HANDLE_VALUE",
                                   MB_OK);
            case IDM_OPEN:
       hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED |
        COINIT_DISABLE_OLE1DDE);
    if (SUCCEEDED(hr))
          MessageBox(hWnd1, L"com is registered"
                                   L"Error 2",
                                   MB_OK);
        IFileOpenDialog *pFileOpen;
        hr = CoCreateInstance(CLSID_FileOpenDialog, NULL, CLSCTX_ALL,
                IID_IFileOpenDialog, reinterpret_cast<void**>(&pFileOpen));
        if (SUCCEEDED(hr))
            hr = pFileOpen->Show(NULL);
            if (SUCCEEDED(hr))
                IShellItem *pItem;
                hr = pFileOpen->GetResult(&pItem);
                if (SUCCEEDED(hr))
                    PWSTR pszFilePath;
                    hr = pItem->GetDisplayName(SIGDN_FILESYSPATH, &pszFilePath);
                    if (SUCCEEDED(hr))
                        MessageBox(NULL, pszFilePath, L"File Path", MB_OK);
    HANDLE hFile1 = CreateFile(pszFilePath, GENERIC_READ,
                              0, NULL, OPEN_EXISTING,
                              FILE_FLAG_SEQUENTIAL_SCAN, NULL);
if (hFile1 = INVALID_HANDLE_VALUE)
    {dwe=GetLastError();
      swprintf_s(dwe5,100,L"%d",dwe);
                        MessageBox(hWnd1, dwe5
                                   L"Error INVALID_HANDLE_VALUE",
                                   MB_OK);
  ReadFile(hFile1, &pbBuff1, sizeof(cb1), (DWORD *)&pcb1, NULL);
pcb1 = 0;
cb1 = 100;
dwCookie    = (DWORD_PTR)hFile1;
pfnCallback1 = NULL ;
dwError= 0;
pfnCallback1(dwCookie,pbBuff1,cb1,pcb1);
EDITSTREAM es1 = { 0 };
es1.pfnCallback = pfnCallback1;
es1.dwCookie    = (DWORD_PTR)hFile1;
es1.dwError =    dwError;
if (SendMessage(richedit1, EM_STREAMIN, SF_RTF, (LPARAM)&es1) && es1.dwError == 0)
CoTaskMemFree(pszFilePath);
        CloseHandle(hFile1);
                    pItem->Release();
            pFileOpen->Release();
        CoUninitialize();
// Basics.cpp : Defines the entry point for the application.
#include "stdafx.h"
#include "Basics.h"
#include "windows.h"
#include "Winuser.h"
#include <stdio.h>
#include "Richedit.h"
#include <shobjidl.h>
#define MAX_LOADSTRING 100
#define ID_BUTTONA      200
#define  ID_BUTTONB 201
// Global Variables:
HINSTANCE hInst;                                // current instance
TCHAR szTitle[MAX_LOADSTRING];                    // The title bar text
TCHAR szWindowClass[MAX_LOADSTRING];            // the main window class name
// Forward declarations of functions included in this code module:
ATOM                MyRegisterClass(HINSTANCE hInstance);
BOOL                InitInstance(HINSTANCE, int);
LRESULT CALLBACK    WndProc(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK    WndProc1(HWND, UINT, WPARAM, LPARAM);
INT_PTR CALLBACK    About(HWND, UINT, WPARAM, LPARAM);
int APIENTRY _tWinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPTSTR    lpCmdLine,
                     int       nCmdShow)
    UNREFERENCED_PARAMETER(hPrevInstance);
    UNREFERENCED_PARAMETER(lpCmdLine);
     // TODO: Place code here.
    MSG msg;
    HACCEL hAccelTable;
    // Initialize global strings
    LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
    LoadString(hInstance, IDC_BASICS, szWindowClass, MAX_LOADSTRING);
    MyRegisterClass(hInstance);
    // Perform application initialization:
    if (!InitInstance (hInstance, nCmdShow))
        return FALSE;
    hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_BASICS));
    // Main message loop:
    while (GetMessage(&msg, NULL, 0, 0))
        if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
            TranslateMessage(&msg);
            DispatchMessage(&msg);
    return (int) msg.wParam;
//  FUNCTION: MyRegisterClass()
//  PURPOSE: Registers the window class.
//  COMMENTS:
//    This function and its usage are only necessary if you want this code
//    to be compatible with Win32 systems prior to the 'RegisterClassEx'
//    function that was added to Windows 95. It is important to call this function
//    so that the application will get 'well formed' small icons associated
//    with it.
ATOM MyRegisterClass(HINSTANCE hInstance)
    WNDCLASSEX wcex;
    wcex.cbSize = sizeof(WNDCLASSEX);
    wcex.style            = CS_HREDRAW | CS_VREDRAW;
    wcex.lpfnWndProc    = WndProc;
    wcex.cbClsExtra        = 0;
    wcex.cbWndExtra        = 0;
    wcex.hInstance        = hInstance;
    wcex.hIcon            = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_BASICS));
    wcex.hCursor        = LoadCursor(NULL, IDC_ARROW);
    wcex.hbrBackground    = (HBRUSH)(COLOR_WINDOW+1);
    wcex.lpszMenuName    = MAKEINTRESOURCE(IDC_BASICS);
    wcex.lpszClassName    = szWindowClass;
    wcex.hIconSm        = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));
     WNDCLASSEX wcex1;    
    wcex1.cbSize = sizeof(WNDCLASSEX);
    wcex1.style            = CS_HREDRAW | CS_VREDRAW;
    wcex1.lpfnWndProc    = WndProc1;
    wcex1.cbClsExtra        = 0;
    wcex1.cbWndExtra        = 0;
    wcex1.hInstance        = hInstance;
    wcex1.hIcon            = NULL;
    wcex1.hCursor        = LoadCursor(NULL, IDC_ARROW);
    wcex1.hbrBackground    = (HBRUSH)(COLOR_WINDOW+1);
    wcex1.lpszMenuName    = MAKEINTRESOURCE ( IDC_BASICS);
    wcex1.lpszClassName    = L"NEW CLASS";
    wcex1.hIconSm        = NULL;
    RegisterClassEx(&wcex1);
    return RegisterClassEx(&wcex);
//   FUNCTION: InitInstance(HINSTANCE, int)
//   PURPOSE: Saves instance handle and creates main window
//   COMMENTS:
//        In this function, we save the instance handle in a global variable and
//        create and display the main program window.
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
   HWND hWnd;
   hInst = hInstance; // Store instance handle in our global variable
   hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
      CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
   if (!hWnd)
      return FALSE;
   ShowWindow(hWnd, nCmdShow);
   UpdateWindow(hWnd);
   return TRUE;
//  FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM)
//  PURPOSE:  Processes messages for the main window.
//  WM_COMMAND    - process the application menu
//  WM_PAINT    - Paint the main window
//  WM_DESTROY    - post a quit message and return
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
    int wmId, wmEvent;
    PAINTSTRUCT ps;
    HDC hdc;
    HWND hwndButton;
    HWND hwndButtona;
    HWND richedit;
    HANDLE hFile;
    HINSTANCE hInstance;
    switch (message)
        DWORD dw;
    WCHAR dw1[100];
    DWORD dw2;
    WCHAR dw3[100];
    DWORD dwpfn;
    WCHAR dwj[100];
   case WM_CREATE:
             hwndButton = CreateWindow(
    L"BUTTON",  // Predefined class; Unicode assumed
    L"OK",      // Button text
    WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,  // Styles
    200,         // x position
    160,         // y position
    150,        // Button width
    100,        // Button height
    hWnd,     // Parent window
    NULL,       // No menu.
    (HINSTANCE)GetWindowLong(hWnd, GWL_HINSTANCE),
    NULL);      // Pointer not needed.
             LoadLibrary(L"Msftedit.dll");
    richedit = CreateWindowEx(
    WS_EX_ACCEPTFILES | WS_EX_CLIENTEDGE,
    MSFTEDIT_CLASS,
    L"MSFTEDIT_CLASS",
    WS_CHILD | WS_VISIBLE |ES_AUTOHSCROLL | ES_LEFT| ES_SELECTIONBAR| ES_SUNKEN | ES_SAVESEL | ES_AUTOVSCROLL ,
    0,
    0,                  // starting x- and y-coordinates
    0,        // width of client area
    0,  
    hWnd,
    NULL,    
    (HINSTANCE)GetWindowLong(hWnd, GWL_HINSTANCE),
     NULL);
if (!richedit)
    dw=GetLastError();
      swprintf_s(dw1,100,L"%d",dw);
                        MessageBox(hWnd, dw1
                                   L"Error richedit",
                                   MB_OK);
 SendMessage(richedit, WM_CONTEXTMENU, 0, 0);
  SetWindowPos(
    richedit,
    NULL,
    180,
    265,
    190,
    25,
    NULL);
           hwndButtona = CreateWindow(
    L"BUTTON",  // Predefined class; Unicode assumed
    L"OK",      // Button text
    WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,  // Styles
    380,         // x position
    265,         // y position
    25,        // Button width
    25,        // Button height
    hWnd,     // Parent window
    (HMENU) ID_BUTTONA,       // No menu.
    (HINSTANCE)GetWindowLong(hWnd, GWL_HINSTANCE),
    NULL);      // Pointer not needed.
        break;
    case WM_COMMAND:
        wmId    = LOWORD(wParam);
        wmEvent = HIWORD(wParam);
        // Parse the menu selections:
        switch (wmId)
        case IDM_ABOUT:
            DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
            break;
            case ID_BUTTONA:
            DWORD_PTR dwCookie;
    dwCookie = 0;
    DWORD   dwError;
    dwError = 0;
    EDITSTREAMCALLBACK EditStreamCallback;
    EditStreamCallback = NULL ;
    EDITSTREAM es;  
    hFile = (HANDLE)dwCookie;   
es.dwCookie    = (DWORD_PTR)hFile;
es.dwError =    dwError;
es.pfnCallback = EditStreamCallback;
    LPBYTE pbBuff;
    pbBuff = NULL;
    LONG cb;
    PLONG pcb;
    pcb = 0;
    DWORD   write;
     WriteFile(hFile, &pbBuff, write, (DWORD *)&pcb, NULL);//
dwpfn=GetLastError();
      swprintf_s(dwj,100,L"%d",dwpfn);
                        MessageBox(hWnd, dwj
                                   L"Problem with write file",
MB_OK);
EditStreamCallback( (DWORD_PTR)hFile ,pbBuff,cb,pcb);
SendMessage(richedit, EM_STREAMOUT, SF_RTF, (LPARAM)&es);
    hFile = CreateFile(L"Again.rtf",GENERIC_WRITE,
                              FILE_SHARE_WRITE, 0, CREATE_NEW,
                              FILE_ATTRIBUTE_NORMAL, NULL);
    if (hFile=INVALID_HANDLE_VALUE)
    dw2=GetLastError();
      swprintf_s(dw3,100,L"%d",dw2);
                        MessageBox(hWnd, dw3
                                   L"INVALID_HANDLE_VALUE",
                                   MB_OK);                  
   HWND hWnd1;
   hWnd1 = CreateWindow(L"NEW CLASS", L"Window 2", NULL,
      0, 0, 980, 700, NULL, NULL, hInstance, NULL);
   dw2=GetLastError();
      swprintf_s(dw3,100,L"%d",dw2);
                        MessageBox(hWnd, dw3
                                   L"INVALID_HANDLE_VALUE",
                                   MB_OK);
   if (!hWnd1)
      MessageBox(hWnd,  L"CreateWindow failed"
                                   L"Error CreateWindow",
                                   MB_OK);
   ShowWindow(hWnd1, SW_SHOW);
   UpdateWindow(hWnd1);
   ShowWindow(hWnd, SW_HIDE);
   return TRUE;
        case IDM_EXIT:
            DestroyWindow(hWnd);
            break;
        default:
            return DefWindowProc(hWnd, message, wParam, lParam);
        break;
    case WM_PAINT:
        hdc = BeginPaint(hWnd, &ps);
        // TODO: Add any drawing code here...
        EndPaint(hWnd, &ps);
        break;
    case WM_DESTROY:
        PostQuitMessage(0);
        break;
    default:
        return DefWindowProc(hWnd, message, wParam, lParam);
    return 0;
LRESULT CALLBACK WndProc1(HWND hWnd1, UINT message, WPARAM wParam, LPARAM lParam)
    int wmId, wmEvent;
    PAINTSTRUCT ps;
    HDC hdc;
    HWND richedit1;
    DWORD dwe;
    WCHAR dwe5[100];
    DWORD dw4;
    WCHAR dw5[100];
    LPBYTE pbBuff1;
    LONG cb1;
    PLONG pcb1;
    DWORD_PTR dwCookie;
    DWORD   dwError;
    EDITSTREAMCALLBACK pfnCallback1;
    HRESULT hr;
    HWND hwndButtonb;
    switch (message)
    case WM_CREATE:
        LoadLibrary(L"Msftedit.dll");
    richedit1 = CreateWindowEx(
        WS_EX_ACCEPTFILES | WS_EX_CLIENTEDGE, MSFTEDIT_CLASS,
    L"MSFTEDIT_CLASS",
    WS_CHILD | WS_VISIBLE |ES_AUTOHSCROLL | ES_LEFT| ES_SELECTIONBAR| ES_SUNKEN | ES_SAVESEL | ES_MULTILINE | ES_AUTOVSCROLL ,
    0,
    0,                  // starting x- and y-coordinates
    0,        // width of client area
    0,  
    hWnd1,
    NULL,    
    (HINSTANCE)GetWindowLong(hWnd1, GWL_HINSTANCE),
     NULL);
     SetWindowPos(
    richedit1,
    NULL,
    0,
    0,
    980,
    700,
    NULL);
if (!richedit1)
    {dw4=GetLastError();
      swprintf_s(dw5,100,L"%d",dw4);
                        MessageBox(hWnd1, dw5
                                   L"Error richedit",
                                   MB_OK);
         hwndButtonb = CreateWindow(
    L"BUTTON",  // Predefined class; Unicode assumed
    L"OK",      // Button text
    WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,  // Styles
    380,         // x position
    265,         // y position
    25,        // Button width
    25,        // Button height
    richedit1,     // Parent window
    (HMENU) ID_BUTTONB,       // No menu.
    (HINSTANCE)GetWindowLong(richedit1, GWL_HINSTANCE),
    NULL);      // Pointer not needed.
    case WM_COMMAND:
        wmId    = LOWORD(wParam);
        wmEvent = HIWORD(wParam);
        // Parse the menu selections:
        switch (wmId)
            case IDM_OPEN:
       hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED |
        COINIT_DISABLE_OLE1DDE);
    if (SUCCEEDED(hr))
          MessageBox(hWnd1, L"com is registered"
                                   L"Error 2",
                                   MB_OK);
        IFileOpenDialog *pFileOpen;
        hr = CoCreateInstance(CLSID_FileOpenDialog, NULL, CLSCTX_ALL,
                IID_IFileOpenDialog, reinterpret_cast<void**>(&pFileOpen));
        if (SUCCEEDED(hr))
            hr = pFileOpen->Show(NULL);
            if (SUCCEEDED(hr))
                IShellItem *pItem;
                hr = pFileOpen->GetResult(&pItem);
                if (SUCCEEDED(hr))
                    PWSTR pszFilePath;
                    hr = pItem->GetDisplayName(SIGDN_FILESYSPATH, &pszFilePath);
                    if (SUCCEEDED(hr))
                        MessageBox(NULL, pszFilePath, L"File Path", MB_OK);
    HANDLE hFile1 = CreateFile(pszFilePath, GENERIC_READ,
                              0, NULL, OPEN_EXISTING,
                              FILE_FLAG_SEQUENTIAL_SCAN, NULL);
if (hFile1 = INVALID_HANDLE_VALUE)
    {dwe=GetLastError();
      swprintf_s(dwe5,100,L"%d",dwe);
                        MessageBox(hWnd1, dwe5
                                   L"Error INVALID_HANDLE_VALUE",
                                   MB_OK);
  ReadFile(hFile1, &pbBuff1, sizeof(cb1), (DWORD *)&pcb1, NULL);
pcb1 = 0;
cb1 = 100;
dwCookie    = (DWORD_PTR)hFile1;
pfnCallback1 = NULL ;
dwError= 0;
pfnCallback1(dwCookie,pbBuff1,cb1,pcb1);
EDITSTREAM es1 = { 0 };
es1.pfnCallback = pfnCallback1;
es1.dwCookie    = (DWORD_PTR)hFile1;
es1.dwError =    dwError;
if (SendMessage(richedit1, EM_STREAMIN, SF_RTF, (LPARAM)&es1) && es1.dwError == 0)
CoTaskMemFree(pszFilePath);
        CloseHandle(hFile1);
                    pItem->Release();
            pFileOpen->Release();
        CoUninitialize();
            break;
        default:
            return DefWindowProc(hWnd1, message, wParam, lParam);
        break;
    case WM_PAINT:
        hdc = BeginPaint(hWnd1, &ps);
        // TODO: Add any drawing code here...
        EndPaint(hWnd1, &ps);
        break;
    case WM_DESTROY:
        PostQuitMessage(0);
        break;
    default:
        return DefWindowProc(hWnd1, message, wParam, lParam);
    return 0;
// Message handler for about box.
INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
    UNREFERENCED_PARAMETER(lParam);
    switch (message)
    case WM_INITDIALOG:
        return (INT_PTR)TRUE;
    case WM_COMMAND:
        if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
            EndDialog(hDlg, LOWORD(wParam));
            return (INT_PTR)TRUE;
        break;
    return (INT_PTR)FALSE;

You should post your question to the appropriate MSDN forum, as this forum is specific to questions regarding Microsoft Certifications.

Similar Messages

  • App crash when using JAVA callbacks from native threads in solaris

    Hi all,
    Sorry for putting the thread here. I did use the native methods forum, I wasnt lucky. I Hope more people would look into this forum, which brings me here.
    I have a solaris application which crashes when I try to callback the JAVA methods and variables from the native code. The description of the problem is below
    Written a native library, the library is multithreaded (i.e) I create a thread using pthread_create() in the native code which performs the operation of calling a JAVA method from the native code. The routine of calling the JAVA method works perfectly elsewhere outside the new thread.
    There are two scenarios I've tested it in
    1. I created a thread (say X) from the main thread (say Y) and made the y to wait until the X is complete using the pthread_join(). The JAVA callbacks works fine when called from Y but the app crashes if done from X.
    2. Did not make the Y to wait until the X is complete, hoping that both will run paralelly and even the the App crashes.
    And to be precise the Y is the thread where the native method is called from JAVA.
    I have tested for any memory leaks or stack corruption by removing the JAVA callbacks and bulding a executable and using purify, the report doesnot hint any such occurances.
    The linker options used for building the shared library is as follows
    ${GPP} ${INC} -G ${LIB} -mt -g -lCstd -lCrun -lpthread ${OBJS} -o <lib-name>
    I wonder if we can create threads in the native code when using JAVA callbacks and even if we can whether it would be appropiate to use the callbacks with in the threads
    Looking forward for any help.
    Regards,
    Vamsi

    Guys... can't any one help me with this problem :(

  • App crash when using JNI callbacks

    Hi all,
    I have a solaris application which crashes when I try to callback the JNI methods from the native code. The description of the problem is below
    Written a native library, the library is multithreaded (i.e) I create a thread using pthread_create() in the native code which performs the operation of calling a JAVA method from the native code. The routine of calling the JAVA method works perfectly from elsewhere.
    There are two scenarios I've tested it in
    1. I created a thread (say X) from the main thread (say Y) and made the y to wait until the X is complete using the pthread_join(). The JAVA callbacks work fine when called from Y but the app crashes if done from X.
    2. Did not make the Y to wait until the X is complete, hoping that both will run paralelly and even the the App crashes.
    And to be precise the Y is the thread where the native method is called from JAVA.
    I have tested for any memory leaks or stack corruption by removing the JAVA callbacks and bulding a executable and using purify, the report doesnot hint any such occurances.
    The linker options used for building the shared library is as follows
    ${GPP} ${INC} -G ${LIB} -mt -g -lCstd -lCrun -lpthread ${OBJS} -o <lib-name>
    I wonder if we can create threads in the native code when using JAVA callbacks and even if we can whether it would be appropiate to use the callbacks with in the threads
    Looking forward for any help.
    Regards,
    Vamsi

    Guys... can't any one help me with this problem :(

  • MIDI in using DLL callback function

    I am trying to get MIDI into LV. The dll used is winmm.dll and the function midiinopen (plus others) is described here:
    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/multimed/htm/_win32_midiinopen.asp
    The main problem is I don't know how to program the Call Library Function Node properly in order to perform the call
    plus set it to start receiving callback data, being midi messages. I have tried creating and registering a User Event and
    passing the Event ref to the dll's "dwCallback" and then trapping the callback in an Event Structure, but nothing happens.
    I have studied the "Communicating with a Windows MIDI Device in LabVIEW" example but it gives no hint since midi out
    does not require the use of callbacks.
    Please advice,
    Stefan

    Vedeja wrote:
    I am trying to get MIDI into LV. The dll used is winmm.dll and the function midiinopen (plus others) is described here:
    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/multimed/htm/_win32_midiinopen.asp
    The main problem is I don't know how to program the Call Library Function Node properly in order to perform the call
    plus set it to start receiving callback data, being midi messages. I have tried creating and registering a User Event and
    passing the Event ref to the dll's "dwCallback" and then trapping the callback in an Event Structure, but nothing happens.
    Damn! Need to make this post shorter as this message
    board just silently told me that it needs to be shorter than 5000 words
    and ate up my lengthy repsonse with no way to get it back.
    You can't configure a Call Library Node to pass a Callback function to
    another function. Callback functions have been alien to LabVIEW for a
    long time with good reasons and what it has now as callback function in
    LabVIEw 7.1 and newer is not directly compatible with C callback
    functions.
    Basically as you want to get data from the callback function back into
    LabVIEW there is really no way around some intermediate software layer
    which in this case almost surely means your own specific wrapper DLL
    written in C.
    If you use LabVIEW 7.1 you could use user events but not in the way you
    describe. Attached is an example of how you can use user events from
    external code. Note the extra DLL you will have to write. You have to
    watch out what data you pass back to the user event as it has to match
    exactly the type you configured the user event for, otherwise LabVIEW
    will simply crash on you.
    For numerics this is quite simply and also shown in the example. For
    strings you can't just pass back a C string pointer but you will have
    to allocate a LabVIEW string handle with
    handle = DSNewHandle(sizeof(int32) + <length of C string>)
    and then copy the C string into it. For specifics about how to do this
    you should refer to the External Code reference manual in your Online
    Bookshelf. Similar rules apply for arrays or clusters for that matter.
    If you want or need to do this for LabVIEW < 7.1 there are two
    possible approaches but both are even less trivial. You could either
    create a wrapper DLL that translates your callback events into LabVIEW
    occurrences and for the data transfer back to LabVIEW you would have to
    implement your own queing too, or you could use the Windows Message
    Queue example somewhere here in the NI examples and adapt it to return
    your specific data. That would solve the data queueing more or less for
    you without having to worry about that.
    Rolf Kalbermatter
    Message Edited by rolfk on 05-22-2006 11:22 AM
    Rolf Kalbermatter
    CIT Engineering Netherlands
    a division of Test & Measurement Solutions
    Attachments:
    userevent.zip ‏27 KB

  • How is Parameters.Result used in callback? How is it different from Parameters.Step.Result?

    Hello,
    I have searched TestStand reference manuals, help, and the forums, and I haven't yet found exactly how Parameters.Result should be used in callbacks (if at all).
    I'm trying to figure out how to take a step that normally is not recorded in the result list, and force it to be recorded on the infrequent occasions that it fails. I'm thinking I should be using the Result, but I'm not sure how.  If I set Parameters.Step.RecordResult = True then the step does get set to record results, but that seems to be permanent in the sequence file and AFTER the failure goes unreported.
    Thanks in advance for your expert help!
    - Gizmogal
    Solved!
    Go to Solution.

    In stepping through the SequenceFilePostResultListEntry I finally discerned the difference between Parameters.Step.Result and Parameters.Result, which is only visible at run time:
    Parameters.Result has a TS container which refers to the current step, giving information such as StepGroup, StepName, StepType, among others. Its results-related properties are equivalent to the Parameters.Step.Result properties as far as I can tell.
    Parameters.Step.Result has a much more extensive TS container of type TEInf which appears to be test executive information.
    It seems kind of backwards from what I would expect, but there it is.
    I'm partway through shifting my paradigm - recording all results and then discarding those not of interest. I ended up adding a status string "RecordAlways" to force some steps to be recorded every time, and I toss any that are not equal to that or "Passed", "Failed", "Error", or "Terminated". It's working pretty well so far.
    Thanks again for your help!
    - Gizmogal

  • Invoking ODI scenario from BPEL using Asynchronous callbacks

    It has been given in many sites that for invoking an odi scenario, odi-public-ws.aar must be uploaded to AXIS2 framework as the web service uses AXIS2 as the web service container. For doing this first the AXIS2 should be deployed in OC4J.
    I am working with a scenario like this. I didnt deploy AXIS2 and neither uploaded the odi-public-ws.aar. Still i am getting the result as success. BPEL is invoking the ODI scenario and callback is happening too.
    I, also tried invoking ODI scenario in a remote system. Got the result for that too. I am using ODI 10.1.3.4 and J-Dev 10.1.3.3 and SOA suite 10.1.3.1.
    Can anyone suggest how without AXIS2 framework the process is success?

    Hi,
    Thanks its working now. I am facing another issue. I do not use parameters in my Scenario. Now when i run my scenario i m getting the following error. I think its because i have not assigned anything to the Variable element. I guess its taking null value for Variable element here and cheking if such a variable exists. Have you come accross such an issue? If so, please sugest remedy.
    java.lang.Exception: Specified variable not found in the Repository : null
         at com.sunopsis.dwg.dbobj.SnpSession.a(SnpSession.java)
         at com.sunopsis.dwg.dbobj.SnpSession.y(SnpSession.java)
         at com.sunopsis.dwg.dbobj.SnpSession.treatSessionPreTrt(SnpSession.java)
         at com.sunopsis.dwg.dbobj.SnpSession.treatSession(SnpSession.java)
         at com.sunopsis.dwg.cmd.DwgCommandScenario.treatCommand(DwgCommandScenario.java)
         at com.sunopsis.dwg.cmd.DwgCommandBase.execute(DwgCommandBase.java)
         at com.sunopsis.dwg.cmd.e.i(e.java)
         at com.sunopsis.dwg.cmd.h.y(h.java)
         at com.sunopsis.dwg.cmd.e.run(e.java)
         at java.lang.Thread.run(Thread.java:619)
    Edited by: silas.john on May 13, 2009 1:29 AM

  • Use of callback in JAAS

    hi
    i don't understand yet the use of the callback
    I notice in sun documentation that NameCallback,for example, Construct a NameCallback with a prompt but in my case (i use JAAS in web application) i don't get the username from prompt but from an inputText
    can anyone explain me this please

    thanks ejp for your help
    but i have another question
    how can i revoke a permission that i have added( with grant) in yhe policy file

  • Error raised when using a CallBack function on a Richtextbox

    Hi,
    I am using a RichTextBox with a Callback VI attached to the Keypress event.  Everytime I cause the kepress event to go off I get the attached error.
    I have created a small project to demonstrate the issue, also attached.
    I'm running Labview 2009 but have seen the issue on other version as well.
    Any ideas on what is causing the error would be most useful.  Have not implemented the CallBack VI correctly or is there some other issue I need to be aware of?
    Thanks
    Attachments:
    Error message.png ‏24 KB
    RichTextBoxCallback.zip ‏23 KB

    Hello Ruffdi,
    In order to get your 8.5 code to work as intended, you should wire the RichTextBox reference to your User Parameter input on the Event Callback (see pic below), and you should see the "KeyPress Detected" appear on your front panel.
    Also, make sure you add a little delay in your while loop, and a Close Reference function at the end of your code right after the while loop, to close the reference you open with the RichTextBox.
    I hope this helps for now, as I cannot find a workaround to the issue we are seeing in LabVIEW 2009.
    Let me work on this slightly more and see what we can do.
    smercurio_fc, thank you kindly for all your help so far, it is much appreciated.
    Kind Regards,
    Michael S.
    Applications Engineer
    NI UK & Ireland

  • Error line 392 in eventoracle.cpp when using activeX callback vi.

    I am using an activeX control built in VC6.0. I followed the instructions to handle the activeX event using the Reg Event Callback node. It is being handled because I have a message box within the handler that does appear. But after the handler executes, LV crashes with the statement that eventoracle.cpp failed at line 392.

    I found that the issue is not the ActiveX event, but where is the event fired from in the ActiveX control. I have a worker thread that calls the parent thread's method to fire the event. If I move the firing of the event outside of this worker thread, I have no problems getting handling the event.

  • Trouble retrieving Button value when using OnPlotAreaMouseUp() Callback function

    I'm using an NiGraph control and have set it up for the OnPlotAreaMouseUp event. I get to the OnPlotAreaMouseUp() callback fine, but the *Button value is always set to 0, and therefore I cannot ascertain which mouse button has been released. The *Shift value seems to work fine however.

    This appears to be a bug in the current version of the graph - I will log a bug report about this issue. The button parameter is set correctly in the PlotAreaMouseDown event, so for now you could work around it by caching the button value in the PlotAreaMouseDown event and evaluating the cached value in the PlotAreaMouseUp event.
    - Elton

  • Acquire data continuous​ly using InstallCom​Callback

    Hi
    I am trying to aquire data (8 Bytes) every 20ms over RS232 using InstallComCallback.
    This is how I am trying to do it :
    // Open and Configure Com port 1
    OpenComConfig (1, "", 9600, 0, 8, 1, 512, 512);
    SetCTSMode (1, LWRS_HWHANDSHAKE_OFF);
    FlushInQ (1);
    FlushOutQ (1);
    InstallComCallback (1, LWRS_RXFLAG, 0, (int)EventChar[0] , Event_Char_Detect_Func, 0); // Actuall event mask and function are some what different 
    while(1)
              processsystemevent();        //bare with typo :/
    when I am running it. It is working fine for 4850 (apprx) data set. after that its stopping automatically. 
    I want to run this callback for really long time (infinte loop) with stopping/ getting inturrept by any means.
    Is it inturrept related problem ??
    How to solve it ??
    Thanks in advance 
    Ankur Verma

    It's hard to guess what's happening with so few informations...
    When you say it's stopping automatically: is the callback simply not being called or does the program crash in any way?
    Are you receiving any error? Are you actually trapping errors in serial functions?
    Please add a few more details so that we can try to figure out what can be happening.
    Proud to use LW/CVI from 3.1 on.
    My contributions to the Developer Zone Community
    If I have helped you, why not giving me a kudos?

  • Connection issue while accessing a jersey restful webservice using aysynch callback method.

    Hi,
    I am having one consumer and producer application. Producer is a Jersey restful webservice deployed in a tomcat server. Consumer side I am using executor service to create one scheduler which will keep on polling and creates a new Thread where I am making a asynch callback req to the service(Producer). But the problem is after my asynch executor thread will die still I can see one connection in deployed server.
    I used yourkit profiler, I can see one thread in runnable state even when the asynch executor dies.
    I think bec of scheduler still there is a connection between client and service. I wanted to create multiple consumer to process multiple thread but because of thread leakage I am not able to proceed.
    Could you please help me on this?

    Err, close the connection?

  • EEM mail with email server using SMTP callback feature

    I am having troubles utilizing the email function.  Our email server has the SMTP callback feature enabled so the applet fails.  Is there a way to respond to this callback using EEM?
    My config
    ip host mail.domain.com 172.16.164.140 172.16.164.139
    event manager environment _mail_smtp mail.domain.com
    event manager environment _mail_domain domain.com
    event manager environment _mail_rcpt [email protected]
    event manager environment _mail_from [email protected]
    The Applet
    event manager applet TEST
    event syslog pattern "%BGP-5-ADJCHANGE: neighbor 10.2.0.1 Down BGP Notification sent"
    action 1.0 info type routername action
    2.0 mail server "$_mail_smtp" to "$_mail_rcpt" from "$_mail_from" subject "$_event_pub_time: T2 down" body "$_syslog_msg" action
    3.0 syslog priority notifications msg "T2 down email send"
    Debug  and log from the test
    May 21 13:33:22.275 CDT: %BGP-5-ADJCHANGE: neighbor 10.2.0.1 Down BGP Notification sent May 21 13:33:22.275 CDT: %BGP-3-NOTIFICATION: sent to neighbor 10.2.0.1 4/0 (hold time expired) 0 bytes
    May 21 13:33:22.287 CDT: %BGP_SESSION-5-ADJCHANGE: neighbor 10.2.0.1 IPv4 Unicast topology base removed from session  BGP Notification sent
    May 21 13:33:22.299 CDT: %HA_EM-5-LOG: MONITOR_TUNNEL_2: BGP Neighbor has gone down on tunnel 2.  Setting track 2 to a down state!!! May 21 13:33:22.307 CDT: %HA_EM-6-LOG: TEST : DEBUG(smtp_lib) : smtp_connect_attempt: 1
    May 21 13:33:52.307 CDT: %HA_EM-6-LOG: TEST : DEBUG(smtp_lib) : smtp_connect connect fail 260
    May 21 13:33:52.307 CDT: %HA_EM-6-LOG: TEST : DEBUG(smtp_lib) : fh_smtp_connect callback timer is awake
    May 21 13:33:52.307 CDT: %HA_EM-3-FMPD_SMTP: Error occurred when sending mail to SMTP server: mail.edwardjones.com : timeout error

    I should explain a bit more about our setup.
    We are utilizing a DMVPN between our remote cisco 2800 router.  This SMTP traffic is riding the tunnel encapsulated within the GRE and Crypto.  We also utilize a zone based firewall  and IPS on the router.  To get to the port 25 of our sever this traffic would have to ride the public internet and not be protected via the VPN.  I am not prepared to follow that method based on security concerns.  So currently we do not allow telnet over the public network and I am confident our main network firewall would block telnet access from outside of our private network.
    So basically I am trying to do this over a private/protected infrastructure.  Perhaps I am using the wrong method?

  • Need an example how to use SCAN_Start with a callback function

    I would appreciate if someone helps me with a working example of how to use SCAN_Start with a callback function. I need just a basic functionality: to specify a channel list (with gains probably), to start a data acquisition task and to receive data buffers utilizing a callback function. t this time whatever I was trying to do caused computer hangups, though it is supposed to be one of the most regular tasks to perform.
    Thank you in advance,
    Mike

    Hello Mike,
    Thank you for contacting National Instruments.
    Attached is an example project which uses a callback function to begin analog acquisition (AI) by calling SCAN_Start. This project acquires from the first 2 channels on your DAQ device. Make sure to modify the device number in the code to match the number of your card.
    Let me know if you have any further questions...
    Sincerely,
    Sean C.
    Applcications Engineer
    National Instruments
    Attachments:
    Acquire_multichannel_61xx.zip ‏11 KB

  • I am trying to write a double buffered data acquisition program using MFC and a callback function.

    i am trying to do a double buffer data acquisition using MFC application framework in Visual Studio.i want to use a callback function to notify when the buffer is half full.do you have some sample reference program that can help me?

    What DAQ board are you using? When you installed NI-DAQ you should have selected to install the support files for VC++. Then there will be several examples on how to do double buffered data acquisition.
    If you have already installed NI-DAQ 6.8 or higher and did not select to include the support files, you can run the NI-DAQ setup program and just add them. If you are using an older version, you will have to uninstall and reinstall.
    Once you have the support files, follow this path to the examples.
    >>Program Files>>National Instruments>>NI-DAQ>>Examaples>>Visual C>>
    If you are doing digital acquistion, goto the di folder, if you are doing analog acquisition goto the ai folder.
    As for the callback function, you can use the NI-DAQ function Config_DAQ_
    Event_Message with DAQEvent Type = 1, where N would equal half your buffer.
    Brian

Maybe you are looking for