Why have VS2017 CodedUI tests Just Stopped Working - visual-studio-2017

I have a coded UI Test that was working fine running locally in debug mode, and randomly just stopped. It still works on other dev pc's but no longer on my PC.
I don't appear to have received any Windows updates or VS updates from when it worked and didn't . What its now doing is clicking the incorrect menu item or not finding a button to click even though its present. The mappings are correct and do work on other machines and its not a timing issue as valid waits are in place and as i said it is working fine on other machines.
Visual Studio Version 15.8.6 Enterprise 2017
Internet Explorer 11.0.90
The exception on the output where it doesn't work seems to indicate an exception with zoom, but the test shouldn't be trying to zoom
IEDOM : ZoomPercentage: Exception when trying to get zoom
The debug output from when it works is as follows
W, 2964, 13, 2018/10/11, 08:48:22.121, 672892725381, QTAgent32_40.exe,
Playback - {8} [SUCCESS] EnsureVisible -
"[Web]ControlType='ComboBox' && TagName='SELECT' &&
Id='ctl00_ContentPlaceHolder1_ddlStore' &&
Name='ctl00$ContentPlaceHolder1$ddlStore' &&
FilterCondition(LabeledBy='', Size='0', Title='', ItemCount='545',
Class='form-control05',
ControlDefinition='name="ctl00$ContentPlaceHolder1$ddlStore',
TagInstance='1')" < Element is clickable > W, 2964, 13, 2018/10/11,
08:48:27.489, 672946394526, QTAgent32_40.exe, IEDOMPlugin: Cannot add
property Src as the validity check failed. Disable
ApplySmartConfiguration flag to bypass validity checks. W, 2964, 13,
2018/10/11, 08:48:27.664, 672948150154, QTAgent32_40.exe, Playback - {9} [SUCCESS] MouseButtonClick -
"[Web]ControlType='Button' && TagName='INPUT' &&
Id='ctl00_ContentPlaceHolder1_btnNext' &&
Name='ctl00$ContentPlaceHolder1$btnNext' &&
FilterCondition(DisplayText='Next', Type='submit', Title='',
Class='btn btn-success m-r-5 m-b-5 btn-xs m-r-5',
ControlDefinition='name="ctl00$ContentPlaceHolder1$btnNext"',
TagInstance='8')" The thread 0x1ce4 has exited with code 0 (0x0). E,
2964, 13, 2018/10/11, 08:48:37.846, 673049974977, QTAgent32_40.exe,
Exception: System.Runtime.InteropServices.COMException Message: Error
HRESULT E_FAIL has been returned from a call to a COM component.
Stack Trace: at Accessibility.IAccessible.get_accRole(Object
varChild) at
Microsoft.VisualStudio.TestTools.UITest.Extension.Msaa.AccWrapper.get_RoleInt()
BaseExceptionMessage: Error HRESULT E_FAIL has been returned from a
call to a COM component.
E, 2964, 13, 2018/10/11, 08:48:37.853, 673050042429, QTAgent32_40.exe,
Exception: System.Runtime.InteropServices.COMException Message: Error
HRESULT E_FAIL has been returned from a call to a COM component.
Stack Trace: at Accessibility.IAccessible.get_accState(Object
varChild) at
Microsoft.VisualStudio.TestTools.UITest.Extension.Msaa.AccWrapper.get_State()
BaseExceptionMessage: Error HRESULT E_FAIL has been returned from a
call to a COM component.
E, 2964, 13, 2018/10/11, 08:48:37.857, 673050081579, QTAgent32_40.exe,
Exception: System.Runtime.InteropServices.COMException Message: Error
HRESULT E_FAIL has been returned from a call to a COM component.
Stack Trace: at Accessibility.IAccessible.get_accRole(Object
varChild) at
Microsoft.VisualStudio.TestTools.UITest.Extension.Msaa.AccWrapper.get_RoleInt()
BaseExceptionMessage: Error HRESULT E_FAIL has been returned from a
call to a COM component.
E, 2964, 13, 2018/10/11, 08:48:37.860, 673050111131, QTAgent32_40.exe,
Exception: System.Runtime.InteropServices.COMException Message: Error
HRESULT E_FAIL has been returned from a call to a COM component.
Stack Trace: at Accessibility.IAccessible.get_accRole(Object
varChild) at
Microsoft.VisualStudio.TestTools.UITest.Extension.Msaa.AccWrapper.get_RoleInt()
BaseExceptionMessage: Error HRESULT E_FAIL has been returned from a
call to a COM component.
W, 2964, 13, 2018/10/11, 08:48:38.247, 673053976659, QTAgent32_40.exe,
Playback - {10} [SUCCESS] MouseButtonClick -
"[Web]ControlType='Hyperlink' && TagName='A' && Id='' && Name='' &&
Target='' && InnerText='Clubs' &&
FilterCondition(AbsolutePath='/test.aspx', Title='', 'test.aspx',
Class='', ControlDefinition='href="test', TagInstance='5')" The thread
0x4b50 has exited with code 0 (0x0). E, 2964, 13, 2018/10/11,
08:48:46.403, 673135533276, QTAgent32_40.exe, Exception:
System.Runtime.InteropServices.COMException Message: Error HRESULT
E_FAIL has been returned from a call to a COM component. Stack Trace:
at Accessibility.IAccessible.get_accRole(Object varChild) at
Microsoft.VisualStudio.TestTools.UITest.Extension.Msaa.AccWrapper.get_RoleInt()
BaseExceptionMessage: Error HRESULT E_FAIL has been returned from a
call to a COM component.
E, 2964, 13, 2018/10/11, 08:48:46.407, 673135575029, QTAgent32_40.exe,
Exception: System.Runtime.InteropServices.COMException Message: Error
HRESULT E_FAIL has been returned from a call to a COM component.
Stack Trace: at Accessibility.IAccessible.get_accState(Object
varChild) at
Microsoft.VisualStudio.TestTools.UITest.Extension.Msaa.AccWrapper.get_State()
BaseExceptionMessage: Error HRESULT E_FAIL has been returned from a
call to a COM component.
E, 2964, 13, 2018/10/11, 08:48:46.411, 673135615631, QTAgent32_40.exe,
Exception: System.Runtime.InteropServices.COMException Message: Error
HRESULT E_FAIL has been returned from a call to a COM component.
Stack Trace: at Accessibility.IAccessible.get_accRole(Object
varChild) at
Microsoft.VisualStudio.TestTools.UITest.Extension.Msaa.AccWrapper.get_RoleInt()
BaseExceptionMessage: Error HRESULT E_FAIL has been returned from a
call to a COM component.
E, 2964, 13, 2018/10/11, 08:48:46.414, 673135644030, QTAgent32_40.exe,
Exception: System.Runtime.InteropServices.COMException Message: Error
HRESULT E_FAIL has been returned from a call to a COM component.
Stack Trace: at Accessibility.IAccessible.get_accRole(Object
varChild) at
Microsoft.VisualStudio.TestTools.UITest.Extension.Msaa.AccWrapper.get_RoleInt()
BaseExceptionMessage: Error HRESULT E_FAIL has been returned from a
call to a COM component.
W, 2964, 13, 2018/10/11, 08:48:46.524, 673136740553, QTAgent32_40.exe,
IEDOMPlugin: Cannot add property Src as the validity check failed.
Disable ApplySmartConfiguration flag to bypass validity checks. W,
2964, 13, 2018/10/11, 08:48:46.712, 673138627073, QTAgent32_40.exe, Playback - {11} [SUCCESS] MouseButtonClick -
"[Web]ControlType='Button' && TagName='INPUT' &&
Id='ctl00_ContentPlaceHolder1_btnNewClub' &&
Name='ctl00$ContentPlaceHolder1$btnNewClub' &&
FilterCondition(DisplayText='Add Club', Type='submit', Title='',
Class='btn btn-success m-r-5 m-b-5 btn-xs m-r-5',
ControlDefinition='name="ctl00$ContentPlaceHolder1$btnNewCl',
TagInstance='8')"
And the output from when it doesnt is
W, 10996, 13, 2018/10/11, 09:09:59.532, 685866771965,
QTAgent32_40.exe, Playback - {8} [SUCCESS]
EnsureVisible - "[Web]ControlType='ComboBox' && TagName='SELECT' &&
Id='ctl00_ContentPlaceHolder1_ddlStore' &&
Name='ctl00$ContentPlaceHolder1$ddlStore' &&
FilterCondition(LabeledBy='', Size='0', Title='', ItemCount='545',
Class='form-control05',
ControlDefinition='name="ctl00$ContentPlaceHolder1$ddlStore',
TagInstance='1')" < Element is clickable > W, 10996, 13, 2018/10/11,
09:10:04.900, 685920458422, QTAgent32_40.exe, IEDOMPlugin: Cannot add
property Src as the validity check failed. Disable
ApplySmartConfiguration flag to bypass validity checks. W, 10996, 13,
2018/10/11, 09:10:05.075, 685922211403, QTAgent32_40.exe, Playback - {9} [SUCCESS] MouseButtonClick -
"[Web]ControlType='Button' && TagName='INPUT' &&
Id='ctl00_ContentPlaceHolder1_btnNext' &&
Name='ctl00$ContentPlaceHolder1$btnNext' &&
FilterCondition(DisplayText='Next', Type='submit', Title='',
Class='btn btn-success m-r-5 m-b-5 btn-xs m-r-5',
ControlDefinition='name="ctl00$ContentPlaceHolder1$btnNext"',
TagInstance='8')" W, 10996, 13, 2018/10/11, 09:10:15.374,
686025189722, QTAgent32_40.exe, IEDOM : ZoomPercentage: Exception when
trying to get zoom:
System.Runtime.InteropServices.InvalidComObjectException: COM object
that has been separated from its underlying RCW cannot be used. at
System.StubHelpers.InterfaceMarshaler.ConvertToNative(Object objSrc,
IntPtr itfMT, IntPtr classMT, Int32 flags) at
Microsoft.VisualStudio.TestTools.UITest.Extension.IE.Communication.Interop.IECommunicatorClass.PageZoom(Object
punkWebBrowser) at
Microsoft.VisualStudio.TestTools.UITest.Extension.IE.DocumentManager.get_ZoomPercentage()
W, 10996, 13, 2018/10/11, 09:10:15.419, 686025645733,
QTAgent32_40.exe, IEDOM : ZoomPercentage: Exception when trying to get
zoom: System.Runtime.InteropServices.InvalidComObjectException: COM
object that has been separated from its underlying RCW cannot be used.
at System.StubHelpers.InterfaceMarshaler.ConvertToNative(Object
objSrc, IntPtr itfMT, IntPtr classMT, Int32 flags) at
Microsoft.VisualStudio.TestTools.UITest.Extension.IE.Communication.Interop.IECommunicatorClass.PageZoom(Object
punkWebBrowser) at
Microsoft.VisualStudio.TestTools.UITest.Extension.IE.DocumentManager.get_ZoomPercentage()
W, 10996, 13, 2018/10/11, 09:10:15.544, 686026897425,
QTAgent32_40.exe, IEDOM : ZoomPercentage: Exception when trying to get
zoom: System.Runtime.InteropServices.InvalidComObjectException: COM
object that has been separated from its underlying RCW cannot be used.
at System.StubHelpers.InterfaceMarshaler.ConvertToNative(Object
objSrc, IntPtr itfMT, IntPtr classMT, Int32 flags) at
Microsoft.VisualStudio.TestTools.UITest.Extension.IE.Communication.Interop.IECommunicatorClass.PageZoom(Object
punkWebBrowser) at
Microsoft.VisualStudio.TestTools.UITest.Extension.IE.DocumentManager.get_ZoomPercentage()
W, 10996, 13, 2018/10/11, 09:10:15.546, 686026913893,
QTAgent32_40.exe, IEDOM : ZoomPercentage: Exception when trying to get
zoom: System.Runtime.InteropServices.InvalidComObjectException: COM
object that has been separated from its underlying RCW cannot be used.
at System.StubHelpers.InterfaceMarshaler.ConvertToNative(Object
objSrc, IntPtr itfMT, IntPtr classMT, Int32 flags) at
Microsoft.VisualStudio.TestTools.UITest.Extension.IE.Communication.Interop.IECommunicatorClass.PageZoom(Object
punkWebBrowser) at
Microsoft.VisualStudio.TestTools.UITest.Extension.IE.DocumentManager.get_ZoomPercentage()
W, 10996, 13, 2018/10/11, 09:10:15.566, 686027113668,
QTAgent32_40.exe, IEDOM : ZoomPercentage: Exception when trying to get
zoom: System.Runtime.InteropServices.InvalidComObjectException: COM
object that has been separated from its underlying RCW cannot be used.
at System.StubHelpers.InterfaceMarshaler.ConvertToNative(Object
objSrc, IntPtr itfMT, IntPtr classMT, Int32 flags) at
Microsoft.VisualStudio.TestTools.UITest.Extension.IE.Communication.Interop.IECommunicatorClass.PageZoom(Object
punkWebBrowser) at
Microsoft.VisualStudio.TestTools.UITest.Extension.IE.DocumentManager.get_ZoomPercentage()
W, 10996, 13, 2018/10/11, 09:10:15.576, 686027216184,
QTAgent32_40.exe, IEDOM : ZoomPercentage: Exception when trying to get
zoom: System.Runtime.InteropServices.InvalidComObjectException: COM
object that has been separated from its underlying RCW cannot be used.
at System.StubHelpers.InterfaceMarshaler.ConvertToNative(Object
objSrc, IntPtr itfMT, IntPtr classMT, Int32 flags) at
Microsoft.VisualStudio.TestTools.UITest.Extension.IE.Communication.Interop.IECommunicatorClass.PageZoom(Object
punkWebBrowser) at
Microsoft.VisualStudio.TestTools.UITest.Extension.IE.DocumentManager.get_ZoomPercentage()
W, 10996, 13, 2018/10/11, 09:10:15.725, 686028707079,
QTAgent32_40.exe, Playback - {10} [SUCCESS]
MouseButtonClick - "[Web]ControlType='Hyperlink' && TagName='A' &&
Id='' && Name='' && Target='' && InnerText='Store Clubs' &&
FilterCondition(AbsolutePath='/test.aspx', Title='', Href='test.aspx',
Class='', ControlDefinition='href="test', TagInstance='5')"

Eventually i found the cause of this, it looked like my IE browser was set to 110% zoom(inadvertently by keyboard i suspect), changing back to 100% and the tests start debugging again successfully

Related

Any info on this SDL_CreateWindow error on windows?

Using SDL to create window for rendering engine that uses Vulkan. Following this code. Following is the snippet of interest:
SDL_Init(SDL_INIT_VIDEO);
SDL_WindowFlags window_flags = (SDL_WindowFlags)(SDL_WINDOW_VULKAN);
_window = SDL_CreateWindow(
"Vulkan Engine",
SDL_WINDOWPOS_UNDEFINED,
SDL_WINDOWPOS_UNDEFINED,
_windowExtent.width,
_windowExtent.height,
window_flags
);
I'm using Visual Studio 2019. Saw this error, built SDL from source as this answer suggested Vulkan flag may not have been enables in the posted binaries. Still, getting error on window creation. Line by line debugging points to this as the line where things break:
return CallWindowProc(data->wndproc, hwnd, msg, wParam, lParam);
in SDL_windowsevents.c.
Exception:
Exception thrown at 0x00007FFF584A4F8E (ntdll.dll) in GraphicsModel.exe: 0xC00000FD: Stack
overflow (parameters: 0x0000000000000001, 0x000000ED25003FB8).
Unhandled exception at 0x00007FFF584A4F8E (ntdll.dll) in GraphicsModel.exe: 0xC000041D: An unhandled exception was encountered during a user callback.
Let me know if I should paste the full stacktrace. Can't figure out what's the cause, any help would be great!
Edit: Callstack (confirms infinite recursion)
ntdll.dll!00007ffb84e44f8e() Unknown
user32.dll!00007ffb83345aa4() Unknown
user32.dll!00007ffb833458ee() Unknown
mfc140ud.dll!00007ffaf0091b05() Unknown
user32.dll!00007ffb83345c1d() Unknown
user32.dll!00007ffb833458ee() Unknown
SDL2.dll!0000000075e4e7d0() Unknown
user32.dll!00007ffb83345c1d() Unknown
user32.dll!00007ffb833458ee() Unknown
mfc140ud.dll!00007ffaf0091b05() Unknown
user32.dll!00007ffb83345c1d() Unknown
user32.dll!00007ffb833458ee() Unknown
THIS BLOCK REPEATS 'n' times
---------------------------------------
SDL2.dll!0000000075e4e7d0() Unknown
user32.dll!00007ffb83345c1d() Unknown
user32.dll!00007ffb833458ee() Unknown
mfc140ud.dll!00007ffaf0091b05() Unknown
user32.dll!00007ffb83345c1d() Unknown
user32.dll!00007ffb833458ee() Unknown
---------------------------------------
SDL2.dll!0000000075e4e7d0() Unknown
user32.dll!00007ffb83345c1d() Unknown
user32.dll!00007ffb833457ec() Unknown
user32.dll!00007ffb83354432() Unknown
> ntdll.dll!00007ffb84ec0b04() Unknown
win32u.dll!00007ffb82ea1524() Unknown
SDL2.dll!0000000075e58ebe() Unknown
SDL2.dll!0000000075e2172d() Unknown
GraphicsModel.exe!VulkanEngine::init() Line 59 C++
GraphicsModel.exe!CMainFrame::OnCreate(tagCREATESTRUCTW * lpCreateStruct) Line 67 C++
[External Code]
GraphicsModel.exe!CGraphicsModelApp::InitInstance() Line 106 C++
[External Code]
GraphicsModel.exe!wWinMain(HINSTANCE__ * hInstance, HINSTANCE__ * hPrevInstance, wchar_t * lpCmdLine, int nCmdShow) Line 26 C++
[External Code]

System.Runtime.InteropServices.SEHException with latest Crystal Report Runtime SP27

I'm upgrading my Crystal report runtime for visual studio from SP16 to the latest one, SP 27, but after building my whole application and running it, when I open a crystal report I end up having an error dialog showing:
Debug Assertion Failed!
Program: C:\WINDOWS\SYSTEM32\mfc140d.dll
File: .../mfc/occsite.cpp
Line:1007
and if I click on Ignore it shows me the stack trace which is this one:
************** Exception Text **************
System.Runtime.InteropServices.SEHException (0x80004005): External component has thrown an exception.
at COleControlSite.AttachWindow(COleControlSite* )
at Microsoft.VisualC.MFC.CWinFormsControlSite.OnHandleCreatedHandler(CWinFormsControlSite* )
at Microsoft.VisualC.MFC.CWinFormsControlSite.OnHandleCreated(CWinFormsControlSite* , Object A_0, EventArgs A_1)
at Microsoft.VisualC.MFC.CWinFormsEventsHelper.OnHandleCreated(Object o, EventArgs args)
at System.Windows.Forms.Control.OnHandleCreated(EventArgs e)
at System.Windows.Forms.Control.WmCreate(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.UserControl.WndProc(Message& m)
at CrystalDecisions.Windows.Forms.CrystalReportViewer.WndProc(Message& msg)
at System.Windows.Forms.Control.ActiveXImpl.System.Windows.Forms.IWindowTarget.OnMessage(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
And then my report is being launched as normal, as if nothing happened.
I'm running VS17, VC Redistributable x64 and x86 14.25.28508, .NET Framework 4.8 and SP any from 25 to 27.
If I install any other SP from 16 to 24 they all work fine. Also on the wiki is says that VS17 is supported from SP21 and higher so I was expecting SP27 to be working fine with VS17 as well.. but it doesnt seem the case, since from SP25 it keeps throwing that exception for me
Looking at the occsite.cpp file this is the function throwing the error
void COleControlSite::AttachWindow()
{
ENSURE_ARG(m_pInPlaceObject!=NULL);
HWND hWnd = NULL;
if (SUCCEEDED(m_pInPlaceObject->GetWindow(&hWnd)))
{
ASSERT(hWnd != NULL);
if (m_hWnd != hWnd)
{
m_hWnd = hWnd;
if (m_pWndCtrl != NULL)
{
ASSERT(m_pWndCtrl->m_hWnd == NULL); // Window already attached?
m_pWndCtrl->Attach(m_hWnd);
ASSERT(m_pWndCtrl->m_pCtrlSite == NULL ||
m_pWndCtrl->m_pCtrlSite == this);
m_pWndCtrl->m_pCtrlSite = this;
}
}
}
}

VS2017 MFC Assert: f:\dd\vctools\vc7libs\ship\atlmfc\include\afxwin2.inl Line:84

next is my code (debug mode run error, release no problem):
"CControlPanel" class derived from CFormView
BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext)
{
m_wndSplitterFrame.CreateStatic(this, 2, 1);
m_wndSplitterFrame.CreateView(0, 0, RUNTIME_CLASS(CControlPanel), CSize(0, 180), pContext); //assert error line
m_wndSplitterSchema.CreateStatic(&m_wndSplitterFrame, 1, 2, WS_CHILD | WS_VISIBLE, m_wndSplitterFrame.IdFromRowCol(1, 0));
m_wndSplitterSchema.CreateView(0, 0, RUNTIME_CLASS(CTabView), CSize(250, 200), pContext);
m_wndSplitterData.CreateStatic(&m_wndSplitterSchema, 1, 2, WS_CHILD | WS_VISIBLE, m_wndSplitterSchema.IdFromRowCol(0, 1));
m_wndSplitterData.CreateView(0, 0, RUNTIME_CLASS(CItemsListView), CSize(700, 0), pContext);
m_wndSplitterData.CreateView(0, 1, RUNTIME_CLASS(CDetailHtmlView), CSize(0, 0), pContext);
....
}
But I commented "OnSize" is no assert error!
void CControlPanel::OnSize(UINT nType, int cx, int cy)
{
CFormView::OnSize(nType, cx, cy);
#ifndef _DEBUG
RECT rect1;
m_CountList.GetWindowRect(&rect1);
ScreenToClient(&rect1);
....
m_CountList.MoveWindow(&rect1);
....
#endif
}
Search said that adding the following code to solve.
AfxWinInit(::GetModuleHandle(NULL),NULL,::GetCommandLine(),0);
But again this error: f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\appinit.cpp
I think this approach is wrong, ask you how to solve this problem?
Looks like OnSize is called before m_CountList's windows is created or not yet attached to Windows window -- has no HWND handle. You get ASSERTs form the framework that you'll try to call API without having a handle. In release build the asserts are removed and that's why you don't get these errors.
The MFC CWnd derived classes have a corresponding Windows window object with HWND on which they call operate attached.
You can test whether your control/windows objects have attached window objects by checking their handle before calling method that call Windows API functions that need window handle.
void CControlPanel::OnSize(UINT nType, int cx, int cy)
{
CFormView::OnSize(nType, cx, cy);
if (m_CountList.GetSafeHwnd())
{
RECT rect1;
m_CountList.GetWindowRect(&rect1);
ScreenToClient(&rect1);
....
m_CountList.MoveWindow(&rect1);
}
....
}
See also ASSERT(::IsWindow(m_hWnd)) fails in Afxwin2.inl

Exception while user callback (MFC)

I have a function with this header
void LiveviewDlg::OnSize(UINT nType, int cx, int cy)
In this function I calculate some coordinates for my controls. I use for this
CRect rect;
GetWindowRect(&rect);
to get some values from my MFC control. After the line
GetDlgItem(IDSTART)->MoveWindow(dialogWidth - 120, 0, 100, 50);
I get the exception
Unhandled exception at 0x5DBA4F14 (mfc120ud.dll) in Liveview.exe: 0xC000041D: Exception while user callback (translated from german to english)
On my Windows 7 system my program works fine. On my windows 10 system I get the exception. I don't know, why is this exception thrown.

D3D - GetSurfaceLevel unhandled exception

I'm creating D3D cursor, so first I made Surface & Texture.
and doing this, I met error on GetSurfaceLevel() Function.
Unhandled exception at 0x5B494B11
0xC0000005: Access violation reading location 0x00000000.
code:
D3DXCreateTextureFromFile( g_D3dDevice, L"cursor1.bmp", &g_cursortex );
g_cursortex->GetSurfaceLevel( 0, &g_surfcursor );
g_D3dDevice->SetCursorProperties( 0, 0, g_surfcursor );
g_D3dDevice->ShowCursor( TRUE );
What should I do?
Unhandled exception at 0x5B494B11 0xC0000005: Access violation reading location 0x00000000.
This kind of error was caused by dereference a NULL pointer, check whether you have create the texture successfully. Make sure g_cursortex not NULL before calling g_cursortex->GetSurfaceLevel( 0, &g_surfcursor );
HRESULT hr = D3DXCreateTextureFromFile( g_D3dDevice, L"cursor1.bmp", &g_cursortex );
if (SUCCEEDED(hr))
{
g_cursortex->GetSurfaceLevel( 0, &g_surfcursor );
g_D3dDevice->SetCursorProperties( 0, 0, g_surfcursor );
}